FeignClient in spring boot 2 - java

I am trying to migrate from spring boot 1.5 tio 2.0 and faced problem: I changed version of spring-cloud-netflix-core from 1.3.4.RELEASE to 2.0.1.RELEASE:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
Unfortunately, feign library imports failed:
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.feign.FeignAutoConfiguration;
import org.springframework.cloud.netflix.feign.FeignClient;
There is no library .feign in new 2.0.1 version. What should I use instead? (connot leave old cloud version because of conflict with spring boot autoconfiguration)

Since the 2.x release Spring Cloud moved the netflix feign classes to their own project.
https://github.com/spring-cloud/spring-cloud-openfeign
You need to update your re-import with the correct package
org.springframework.cloud.openfeign

You need to import feign as an independent dependency starting from 2.X release:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>

Related

Which Spring Cloud AWS version should be used with Spring Boot 3?

I am trying to make SqsListener work but I can't with Spring Boot 3, it simply doesn't receive anything. When I change Spring Boot version back to 2.X everything's work perfectly.
I am using 2.4.2 version of Spring cloud:
...
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-starter-aws-messaging</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-dependencies</artifactId>
<version>2.4.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Can you please point me to the correct version of spring cloud?
Would I need to use milestone version for that?
It doesn't work as version 2.4.2 of spring-cloud-starter-aws-messaging relies on spring.factories for Spring Boot autoconfiguration, but the support for that has been removed in Spring Boot 3.0.0. See https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#auto-configuration-files.
You can enable the auto configuration by creating the following file
src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
# content
io.awspring.cloud.autoconfigure.messaging.SqsAutoConfiguration
But, it probably won't work anyway as spring-cloud-aws also relies on classes from Spring Messaging that were deprecated and removed in Spring 6 (which is used in Spring Boot 3), specifically org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver.
You'll have to wait for Spring Cloud AWS to support Spring Boot 3. They are working on Spring Cloud AWS 3.0.0, but I don't think it has a release date yet. https://github.com/awspring/spring-cloud-aws

How to add properly Data REST dependency in Spring Boot Maven project?

I try to add Spring Data REST dependency using this dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
After adding this dependency I catch an exception - java.lang.NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;
And the Action suggestion: Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry
I tried to add this dependency to fix the problem:
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
But it didn't help me.
How could I fix this problem?
I use Spring Boot version - 2.2.7.RELEASE, Maven version - 3.3.9

Spring Boot BOM for non boot spring project

I'd like to use spring boot specific BOM for my non-boot spring project. Is it acceptable to include spring-boot-dependencies or platform-bom and what's better?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>...</version>
<type>pom</type>
<scope>import</scope>
</dependency>
or
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>...</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Thanks.
Both are valid approaches.
To quote the Spring IO Platform documentation :
Spring IO Platform builds on top of Spring Boot
So, they provide what you search for a non spring boot application : a set of consistent dependencies and some specific beans provided by Spring Boot.
Now, personally, I would chose org.springframework.boot:spring-boot-dependencies as Spring Boot is mature, have an important and active community and is often updated.
See the spring-boot github.
It is not the case of the spring-io/platform.

Sprint Boot and Elastic Search Connection issue

I'm creating an application using Spring Boot and also Elastic-Search. Spring application part is working. And also when I start Elastic server, it's also running well. No issues at all. I can test it via POSTMAN and also CURL. Adding and also searching works well.
But when I run the application, i'm getting following issues.
This is the issue i'm getting in the IDE. (which means from my java application)
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{127.0.0.1:9300}]
And this is the issue i'm getting from the Elasctic server on my local system.
java.lang.IllegalStateException: Received message from unsupported version: [2.0.0] minimal compatible version is: [5.0.0]
These are the libraries I'm using.
Spring Boot 1.5.1.RELEASE
Spring Boot Starter Data Elasticsearch 1.5.1.RELEASE
Spring Data Elasticsearch 2.10.RELEASE
Elastic Search 5.0
I think this is a issue with Elastic and above library version mismatch.
I'm new to Elastic and also Spring. The version issue is here.
https://github.com/spring-projects/spring-data-elasticsearch/wiki/Spring-Data-Elasticsearch---Spring-Boot---version-matrix
And also here is my pom.xml. If I need to update any library, can anyone tell me what's that ? And also tell me how to update those libraries ? Can I update them without changing to my source code ?
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<artifactId>springboot-springdata-elasticsearch-example</artifactId>
<packaging>jar</packaging>
<url>https://www.mkyong.com</url>
<version>1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Runtime, for Embedded Elasticsearch,
comment this if connect to external elastic search server-->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Package as an executable jar/war -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
In this pom.xml , I can't find all the dependencies too.
According to the versions matrix that you provided, the spring boot version that you're using is not compatible with ElasticSearch 5.x instances. So, i think you have 3 options:
If you really need to work with SpringBoot 1.5.1 using ElasticSearch 5.0, you should add the maven dependencies related to ElasticSearch 5.0 and implement your own DAO service.
You can try to downgrade your ElasticSearch version to 2.4 in order to make it compatible with your current spring boot version.
Maybe you can try to use the recent spring boot version (1.5.4) because arcording to the spring-data-elasticsearch project (https://github.com/spring-projects/spring-data-elasticsearch/), the last version supports ElasticSearch 5.x, so probably it could be the easiest way.
Please let me know if any of options above was useful for you.

Using hibernate-validator with javax.validation:validation-api:1.1.0.Final) and glassfish-embedded-all?

I am using the Glassfish library like this in my webapp to be in sync with Glassfish embedded libs directory during development. How can I update it to be able to use javax.validation.api 1.1.0?
This is the glassfish dependency:
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>4.0-b72</version>
<scope>provided</scope>
</dependency>
Unfortunately this glassfish lib collection is still using an older javax.validation-api lib. But to use:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.0.Final</version>
</dependency>
I need a newer one. Is there any way to update the Glassfish libs if there isn't a new version for glassfish-embedded-all.
How do you solve such issues?
Thanks in advance.
Is there any way to update the Glassfish libs if there isn't a new
version for glassfish-embedded-all.
Yes, but there is also a new version which is the 4.0 final build of GlassFish.
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>4.0</version>
<scope>provided</scope>
</dependency>
This version includes Hibernate Validator 5.0.0 which already depends on Validation API 1.1.0.
If you need a newer version then Hibernate Validator 5.0.0 you have to extract the corresponding GlassFish module (in this case bean-validation.jar), change the pom.xml to depend on the desired version and rebuild it with mvn package.
See also:
Bean-Validation 1.1 in Glassfish 4.0 - CDI Injection not working as intended
Trouble starting Hibernate Validator due to Bean Validation API
How to upgrade the hibernate-validator 4.3.0.Final to the Glassfish 3.1.2?

Categories