java.lang.NoSuchMethodError during service startup with kafka - spring-boot

I am trying to make a small microservices project to touch kafka.
To start kafka I am using docker compose:
kafka-server:
image: spotify/kafka
ports:
- 2181:2181
- 9092:9092
environment:
ADVERTISED_PORT: 9092
CONSUMER_THREADS: 1
TOPICS: serverInputTopic,clientInputTopic
To add kafka support in my service I use following in POM
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/>
</parent>
<properties>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-kafka</artifactId>
</dependency>
</dependencies>
Only usage in code is annotation on runner class
#EnableBinding(Sink.class)
and annotation on listener method
#StreamListener(Sink.INPUT)
I start kafka without problems, but when I start my service I get following error:
ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: F
ailed to start bean 'inputBindingLifecycle'; nested exception is java.lang.NoSuchMethodError: org.springframework.kafka.listener.ContainerProperties.setAuthorizationExceptionRetryInterval(Ljava/time/Duration;)V
What can be done to fix it? Thanks!

This is a known issue as reported here: https://github.com/spring-cloud/spring-cloud-release/issues/70
You need to upgrade the version of Spring Integration Kafka to 2.1.0 to fix the issue.

resolved with external dependency
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.4.6.RELEASE</version>
</dependency>

Related

Spring Cloud Kubernetes Loadbalancer issue with Spring Boot 2.6.6

I am using spring boot 2.6.6 and spring cloud 2021.0.2 version with spring cloud kubernetes loadbalancer and spring cloud kubernetes all.
But I am getting error Application failed to start below are the dependencies
<properties>
<spring-cloud.version>2021.0.2</spring-cloud.version>
<spring-boot.version>2.6.6</spring-boot.version>
</properties>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-all</artifactId>
<version>1.1.10.RELEASE</version>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-dependencies</artifactId>
<version>1.1.10</version>
</dependency>
</dependencies>
</dependencyManagement>
Error:
2022-05-24 01:05:51.399 ERROR 14884 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Error processing condition on org.springframework.cloud.loadbalancer.config.LoadBalancerCacheAutoConfiguration$DefaultLoadBalancerCacheManagerConfiguration.defaultLoadBalancerCacheManager
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.6.6.jar:2.6.6]
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:193) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:153) ~[spring-context-5.3.18.jar:5.3.18]
Process finished with exit code 1
Please if someone can help to understand what is the going wrong here.
Any help is much appreciated.
Thanks !!
Thanking all to share your views via comments. I have figured out the answer.
I see below dependency seems to be working fine with latest spring boot 2.6.6 or 2.7.0
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-fabric8-all</artifactId>
<version>2.1.2</version>
</dependency>
It seems this is similar to what below ones use to provide, such as config or load balancer etc. certainly the dependencies are renamed as you can see.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-all</artifactId>
<version>1.1.10.RELEASE</version>
</dependency>

Error creating bean with name 'compositeCompatibilityVerifier'

I am using Spring Boot 2.5.5 with Spring Cloud Version 2020.0.4 but when I am trying to run the application I am getting below exception -
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'compositeCompatibilityVerifier' defined in class path resource [org/springframework
/cloud/configuration/CompatibilityVerifierAutoConfiguration.class]: Bean instantiation
via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.cloud.configuration.CompositeCompatibilityVerifier]: Factory
method 'compositeCompatibilityVerifier' threw exception; nested exception is
org.springframework.cloud.configuration.CompatibilityNotMetException
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.4</spring-cloud.version>
</properties>
<dependencies>
<!-- Below jar file also has same Spring Boot Version -->
<dependency>
<groupId>com.another.project</groupId>
<artifactId>commons</artifactId>
<version>1</version>
<scope>compile</scope>
</dependency>
<!-- other spring boot dependency -->
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
I have another project jar included in pom which also has same Spring Boot Version that I doubt cause the issue but not sure how?
Your pom looks good. The only thing I would suggest is to check the spring components compatibility. The spring.io page you have a compatibility matrix, and you should double-check is the version you are trying to use compatible with spring boot.
Second thing you may try, is to not have a parent POM at all, but import spring boot, and spring cloud dependencies from their pom-s.
You added spring cloud, for spring boot do:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
I had the same issue , when i used spring-cloud.version : 2020.0.3 and resolved it by using the version
<spring-cloud.version>2021.0.3</spring-cloud.version>
Check out the compatibility of the spring-cloud you are using with your spring-boot version: Spring-Cloud

Spring Boot with Hystrix

I am using Spring Boot with Hystrix for my university project.
The problem I have is when I add Netflix Hystrix dependency to pom.xml file and run the program, It throws an Error called AbstractMethodError : null, but without Netflix Hystrix dependency program runs without any error. How can I slove this?
These are my dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
This is due to dependency mismatch. Application is trying to call an abstractt method but it doesn't find that method. So, it is throwing the null exception.
Use two dependency netflix-hystrix-dashboard and hystrix as below.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>

Spring Boot 2 fails starting due to Hystrix?

I started investigating to migrate a Spring Boot application from 1.5.x to 2.
This appliication has a dependency to hystrix, which does not be compatible to Spring Boot 2 yet.
When I have the following in my pom:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.4.RELEASE</version>
</dependency>
I get the following error when starting the application:
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:125)
Anybody has experienced the same?
Is there a solution yet?
I have faced similar issue while integrating hystrix for my spring boot microservice that uses spring boot 2.0.x.
Instead of
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>${spring-hystrix.version}</version>
</dependency>
I have moved to
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>${spring-hystrix.version}</version>
</dependency>
Spring boot 2.0.x application starts fine with the spring-cloud-starter-netflix-hystrix dependency without this issue.
For SpringBoot 2.0 version artifactID has been changed. Old dependency is
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>${spring-hystrix.version}</version>
</dependency>
Use this new updated dependency with latest version
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.8.RELEASE</version>
</dependency>
for recent release version you can check MVNrepository
After a bit further research I found a solution by adding the following to the pom file:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
all versions of spring-cloud-dependenciesseem to be incompatible to Spring Boot 2.x.x
I had this problem starting Spring Boot 2 as well because spring-cloud-starter-hystrix was a dependency I used in my project. However I found that spring-cloud-starter-hystrix has been deprecated. I also found the feign classes I was using in there have been moved to spring-cloud-openfeign (https://github.com/spring-cloud/spring-cloud-openfeign). So all I did was remove spring-cloud-starter-hystrix from my dependency and added spring-cloud-openfeign instead. This works perfectly for me.
Basically I replaced
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-hystrix', version: '1.4.4.RELEASE'
with
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '2.0.0.RELEASE'
and Spring Boot 2 is ready to go. Hope this helps.
NB: I use Gradle, you can easily find the maven pom dependency equivalents if necessary.
I faced a similar problem with Spring Boot 2, concisely 2.2.0.RELEASE. My mvn project compiled well but Spring Boot application stopped starting, without showing any real hints.
The solution that worked was using the artifact spring-cloud-starter-netflix-hystrix instead of spring-cloud-starter-hystrix from the same group. Then you can use the same same version as Spring Boot to retrieve the dependency.
From old pom.xml :
<!-- hysterix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
New part in working pom.xml:
<!-- hysterix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>${spring.boot.version}</version>
</dependency>
After some time spent on researching and testing, here is what I found and noticed
I think that in the latest Spring Boot version (2.5.x), the Hystrix looks to be deprecated or I just couldn't find out way to add it as a dependency.
So I downgraded the Spring boot version to 2.3.x where I managed to run the application
So here is how my working pom.xml looks like:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.hldservices</groupId>
<artifactId>payment-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringCloudPaymentCircuitBreakerApplication</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>Hoxton.SR11</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Keep in mind that I had to add following configuration in my Project:
SpringCloudPaymentCircuitBreakerApplication(main class)
#EnableHystrix
#EnableHystrixDashboard
application.propreties
management.endpoints.web.exposure.include=*
hystrix.dashboard.proxyStreamAllowList=*

Hibernate Search not working in Spring Boot

I am using Spring Boot and I am trying to use Hibernate Search. I followed this tutorial but I got the exception:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class
org.hibernate.search.cfg.Environment
application.properties
spring.jpa.properties.hibernate.search.default.directory_provider=filesystem
spring.jpa.properties.hibernate.search.default.indexBase=/home
Pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>5.5.3.Final</version>
</dependency>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>4.5.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
This should solve your problem cause it works well at my spring boot app. Good luck!

Resources