Spring Data Rest and spring-data-rest-hal-browser integration using Spring Boot - spring

Problem
The Spring Data REST Reference Documentation says that
dependencies {
compile 'org.springframework.data:spring-data-rest-hal-browser'
}
is enough to integrate HAL browser with Spring Data Rest while using Spring Boot but Gradle complains this dependency cannot be found unless I specify particular version so I fixed it by specifying the latest one available in central repository (there is no other version available in the repository). After specifying the version the dependency is resolved but I get an error during Spring Boot container initialization:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.repository.support.Repositories]: Factory method 'repositories' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cameraRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 151 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cameraRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1572)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:966)
at org.springframework.data.repository.support.Repositories.cacheRepositoryFactory(Repositories.java:95)
at org.springframework.data.repository.support.Repositories.populateRepositoryFactoryInformation(Repositories.java:88)
at org.springframework.data.repository.support.Repositories.<init>(Repositories.java:81)
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.repositories(RepositoryRestMvcConfiguration.java:182)
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0.CGLIB$repositories$11(<generated>)
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0$$FastClassBySpringCGLIB$$ec6a4119.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0.repositories(<generated>)
at sun.reflect.NativeMetssorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 152 more
Caused by: java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
... 173 more
However my application initializes successfully and works as expected if I remove spring-data-rest-hal-browser:2.4.0.RELEASE dependency.
Question
How can I setup my build.gradle correctly to have my application integrated with HAL browser properly?
build.gradle
buildscript {
ext {
springBootVersion = '1.2.7.RELEASE'
}
repositories {
mavenCentral()
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
}
[...]
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-remote-shell')
compile('org.springframework.data:spring-data-rest-hal-browser:2.4.0.RELEASE')
compile('org.projectlombok:lombok:1.16.6')
compile name: 'ojdbc6'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc:1.0.0.RELEASE')
}

The automatic version management for the HAL browser only works starting with Spring Boot 1.3.0 which is at the release candidate stage and should be released very soon. The release candidate is very stable for me, so you may consider giving that a try by updating your build to 1.3.0.RC1 which I would expect would fix the issue, something like this:
buildscript {
ext {
springBootVersion = '1.3.0.RC1'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone/' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE"
}
}
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-remote-shell')
compile('org.springframework.data:spring-data-rest-hal-browser')
compile('org.projectlombok:lombok:1.16.6')
compile name: 'ojdbc6'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
}
You can see the managed dependency versions for 1.3.0.RC1 here:
http://docs.spring.io/spring-boot/docs/1.3.0.RC1/reference/htmlsingle/#appendix-dependency-versions
You'll notice if you look at the managed dependency versions for 1.2.7 that neither spring-data-rest-hal-browser nor spring-restdocs-mockmvc are present.

The package was renamed to spring-data-rest-hal-explorer. Here's an example of a modern configuration of HAL with Spring Boot 2 with automatic version management.
Maven example:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-explorer</artifactId>
</dependency>
Gradle example:
plugins {
id "io.spring.dependency-management" version <<version>>
}
dependencies {
implementation('org.springframework.data:spring-data-rest-hal-explorer')
}

Related

Error starting spring boot - "An attempt was made to call a method that does not exist"

I am trying to upgrade the Spring version for one of our projects.
The project structure is as listed below:
internalToolApp
internalToolAppServiceTier
The packages of the 2 sub-projects are listed below:
build.gradle of internalToolApp
buildscript {
ext {
springBootVersion = '2.6.9'
}
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
dependencies {
classpath 'org.ajoberstar:grgit:1.7.2'
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
if (project.hasProperty("projVersion")) {
version = project.projVersion
} else {
version = "0.0-SNAPSHOT"
}
group = 'internalToolGroup'
// In this section you declare where to find the dependencies of your project
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
dependencies {
compile project(':internalToolAppServiceTier')
compile('org.springframework.boot:spring-boot-starter-web:2.6.9')
compile('com.github.ulisesbocchio:jasypt-spring-boot:2.1.0')
compile 'com.visa.commons.security.protectconfig:protectconfig-core:2.7.0'
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:3.1.4')
compile 'com.hazelcast:hazelcast-enterprise-all:4.2.1'
compile("com.hazelcast:hazelcast-spring:4.2.1")
compile("org.projectlombok:lombok:1.18.10")
compile('org.apache.tomcat:tomcat-jdbc:8.5.37')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0')
// Log4j 2
compile ('org.apache.logging.log4j:log4j-core:2.17.1')
compile ('org.apache.logging.log4j:log4j-api:2.17.1')
compile ('org.apache.logging.log4j:log4j-slf4j-impl:2.17.1')
compile ("commons-lang:commons-lang:2.6")
compile('org.apache.poi:poi:4.1.2')
compile('org.apache.poi:poi-ooxml:4.1.2')
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
bootJar {
exclude ("application.properties")
exclude ("database.properties")
exclude ("filetransfer.properties")
exclude ("mongo_local_application.properties")
}
task setupProject {
doFirst {
File dir = new File("$buildDir/../../../coreconfig_commons")
if(!dir.exists()) {
def grgit = org.ajoberstar.grgit.Grgit.clone(dir: "$buildDir/../../../anotherInternalTool", uri: "https://.....git")
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
build.gradle of internalToolAppServiceTier
buildscript {
ext {
springBootVersion = '2.6.9'
}
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
dependencies {
classpath 'org.ajoberstar:grgit:1.7.2'
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'maven'
apply plugin: 'maven-publish'
if (project.hasProperty("projVersion")) {
version = project.projVersion
} else {
version = "0.0-SNAPSHOT"
}
group = 'internalToolGroup'
// In this section you declare where to find the dependencies of your project
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
configurations.all {
if (!project.hasProperty("local")) {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
dependencies {
if (project.hasProperty("local")) {
compile project(':CommonServiceTier')
compile project(':CommonUtility')
compile project(':CommonDBTier')
} else {
compile(group: 'internalToolGroup', name: 'CommonServiceTier', version: version){ changing = true }
compile(group: 'internalToolGroup', name: 'CommonUtility', version: version){ changing = true }
compile(group: 'internalToolGroup', name: 'CommonDBTier', version: version){ changing = true }
}
compile('org.springframework.boot:spring-boot-starter-web:2.6.9')
compile('org.springframework:spring-tx:5.0.12.RELEASE')
compile('com.github.ulisesbocchio:jasypt-spring-boot:2.1.0')
compile 'com.hazelcast:hazelcast-enterprise-all:4.2.1'
compile("com.hazelcast:hazelcast-spring:4.2.1")
compile("org.projectlombok:lombok:1.18.10")
compile("org.mongodb:mongo-java-driver:3.9.1")
compile('org.springframework.data:spring-data-mongodb:3.2.0')
compile 'com.fasterxml.jackson.core:jackson-core:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.4'
compile('org.mybatis:mybatis:3.5.0')
compile('org.mybatis:mybatis-spring:2.0.0')
compile 'org.apache.velocity:velocity:1.7'
compile 'org.apache.velocity.tools:velocity-tools-generic:3.0'
compile('org.apache.poi:poi:4.1.2')
compile('org.apache.poi:poi-ooxml:4.1.2')
compile('com.ibm.db2:db2jcc_license_cisuz:1.0')
compile('com.ibm.db2:db2java:1.0')
compile('com.ibm.db2:jcc:11.5.0.0')
// Log4j 2
compile ('org.apache.logging.log4j:log4j-core:2.17.1')
compile ('org.apache.logging.log4j:log4j-api:2.17.1')
compile ('org.apache.logging.log4j:log4j-slf4j-impl:2.17.1')
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
When I run this project internalToolApp, i get some output, showing that the application is able to run, but after some time, the application fails & i get below error in the console:
[2023-01-26 16:59:55,238] [CompanyInternalTool] -- [...]- [main] WARN org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext [] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongo' threw exception; nested exception is java.lang.NoSuchMethodError: com.mongodb.MongoClientSettings$Builder.uuidRepresentation(Lorg/bson/UuidRepresentation;)Lcom/mongodb/MongoClientSettings$Builder;
Jan 26, 2023 4:59:55 PM com.hazelcast.core.LifecycleService
INFO: hz.client_1 [dev] [4.2.1] HazelcastClient 4.2.1 (20210630 - 6145014, 06a4018) is SHUTTING_DOWN
Jan 26, 2023 4:59:55 PM com.hazelcast.client.impl.connection.ClientConnectionManager
INFO: hz.client_1 [dev] [4.2.1] Removed connection to endpoint: [10.93.88.241]:5701:2c82e08d-47f2-44ef-a24e-d539a81aac35, connection: ClientConnection{alive=false, connectionId=1, channel=NioChannel{/127.0.0.1:55728->localhost/127.0.0.1:5701}, remoteAddress=[10.93.88.241]:5701, lastReadTime=2023-01-26 16:59:54.312, lastWriteTime=2023-01-26 16:59:54.283, closedTime=2023-01-26 16:59:55.241, connected server version=4.2.1}
Jan 26, 2023 4:59:55 PM com.hazelcast.core.LifecycleService
INFO: hz.client_1 [dev] [4.2.1] HazelcastClient 4.2.1 (20210630 - 6145014, 06a4018) is CLIENT_DISCONNECTED
Jan 26, 2023 4:59:55 PM com.hazelcast.core.LifecycleService
INFO: hz.client_1 [dev] [4.2.1] HazelcastClient 4.2.1 (20210630 - 6145014, 06a4018) is SHUTDOWN
Jan 26, 2023 4:59:55 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service [Tomcat]
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer.applyUuidRepresentation(MongoPropertiesClientSettingsBuilderCustomizer.java:67)
The following method did not exist:
com.mongodb.MongoClientSettings$Builder.uuidRepresentation(Lorg/bson/UuidRepresentation;)Lcom/mongodb/MongoClientSettings$Builder;
The calling method's class, org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer, is available from the following locations:
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.6.9/143e3b88bbf01a87d4877196c715e3b154d5e00c/spring-boot-autoconfigure-2.6.9.jar!/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.class
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.6.11/40e0e3011e8549b4591a0a3f26d21ba5978b6ed1/spring-boot-autoconfigure-2.6.11.jar!/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.class
The calling method's class was loaded from the following location:
file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.6.9/143e3b88bbf01a87d4877196c715e3b154d5e00c/spring-boot-autoconfigure-2.6.9.jar
The called method's class, com.mongodb.MongoClientSettings$Builder, is available from the following locations:
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.mongodb/mongo-java-driver/3.9.1/d313237180bf9f2f82e12f503d9617e6b070f792/mongo-java-driver-3.9.1.jar!/com/mongodb/MongoClientSettings$Builder.class
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.mongodb/mongodb-driver-core/4.2.3/ac8159055a465139c643355aa3af7f4c050bceb2/mongodb-driver-core-4.2.3.jar!/com/mongodb/MongoClientSettings$Builder.class
The called method's class hierarchy was loaded from the following locations:
com.mongodb.MongoClientSettings.Builder: file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.mongodb/mongo-java-driver/3.9.1/d313237180bf9f2f82e12f503d9617e6b070f792/mongo-java-driver-3.9.1.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer and com.mongodb.MongoClientSettings$Builder
I found a similar StackOverflow post [here](Error starting spring boot "An attempt was made to call a method that does not exist") that seems to indicate there is a duplicate package, I'm not quite sure how to detect that as I'm new to this.
Would anyone be able to provide a solution or guidance on what I should do?
Following #Pritam Sadhukhan's suggestion, i get the same error, althought slightly different, it mentions different versions of the same package causing issues
[2023-01-30 11:39:20,876] [CompanyInternalTool] -- [...]- [main] ERROR org.springframework.boot.SpringApplication [] - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$JdbcTransactionManagerConfiguration': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$JdbcTransactionManagerConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader#73d16e93]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:289) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1302) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1219) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.21.jar:5.3.21]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.21.jar:5.3.21]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.9.jar:2.6.9]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745) [spring-boot-2.6.9.jar:2.6.9]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:420) [spring-boot-2.6.9.jar:2.6.9]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.6.9.jar:2.6.9]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317) [spring-boot-2.6.9.jar:2.6.9]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-2.6.9.jar:2.6.9]
at com.visa.coreconfig.pedit.CoreConfigPeditApp.main(CoreConfigPeditApp.java:154) [main/:?]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$JdbcTransactionManagerConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader#73d16e93]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267) ~[spring-beans-5.3.22.jar:5.3.22]
... 18 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/jdbc/support/JdbcTransactionManager
at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_351]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:1.8.0_351]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[?:1.8.0_351]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267) ~[spring-beans-5.3.22.jar:5.3.22]
... 18 more
Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.support.JdbcTransactionManager
at java.net.URLClassLoader.findClass(URLClassLoader.java:387) ~[?:1.8.0_351]
at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[?:1.8.0_351]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[?:1.8.0_351]
at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_351]
at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_351]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:1.8.0_351]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[?:1.8.0_351]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267) ~[spring-beans-5.3.22.jar:5.3.22]
... 18 more
Deinum,
Is this what the build.gradle should look like?
jackson
Replace
dependencies {
compile 'com.fasterxml.jackson.core:jackson-core:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.4'
}
with
dependencies {
compile('org.springframework.data:spring-boot-starter-json')
}
mongo
Remove
compile("org.mongodb:mongo-java-driver:3.9.1")
compile('org.springframework.data:spring-data-mongodb:3.2.0')
with
compile('org.springframework.data:spring-data-mongodb:3.2.0')
spring-boot-starter-web
Replace
compile('org.springframework.boot:spring-boot-starter-web:2.6.9')
with
compile('org.springframework.boot:spring-boot-starter-web')
Is this all? or did i miss something
Can you please change the build.gradle of internalToolAppServiceTier and replace the following respectively?
compile('org.springframework:spring-tx:5.3.21')
Replace
compile('org.springframework.data:spring-data-mongodb:3.2.0')
to
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.7.2'

Error creating bean with name org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration (Using Gradle)

Building jar file works through the terminal computer path % ./gradlew build, and application runs computer path % java -jar name.jar.
Why not through IntelliJ?
*Secondary Issue -
When I try to upload the jar file built through the terminal to AWS Beanstalk I get a validation error.
*Primary Issue -
The application runs in IntelliJ.
After I have completed the Project Structure setup, and the Build Artifacts execution. The new .jar file fails to run,
throwing the exception below.
Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
build.gradle:
plugins {
id 'org.springframework.boot' version '2.6.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'application'
}
group = 'com.example'
version = 'api'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
runtimeOnly 'mysql:mysql-connector-java'
}
test {
useJUnitPlatform()
}
mainClassName = 'com.example.name.applicationame'
task fatJar(type: Jar) {
bootJar {
launchScript()
}
manifest {
attributes 'Main-Class': "${mainClassName}"
duplicatesStrategy = 'include'
}
archiveBaseName = "name"
from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/name?useSSL=true
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Thanks!

spring-cloud-stream sample projects raises NoSuchBeanDefinitionException of KafkaStreamsFunctionProcessor

I'm trying to touch spring-cloud-stream, and creating a sample project of the official blog.
Implementation is totally same as the article.
#SpringBootApplication
public class SimpleConsumerApplication {
#Bean
public java.util.function.Consumer<KStream<String, String>> process() {
return input ->
input.foreach((key, value) -> {
System.out.println("Key: " + key + " Value: " + value);
});
}
}
I've selected Cloud Stream and Spring for Apache Kafka Stream on Spring initializr, and added ShadowJar. Now my build.gradle is like this.
plugins {
id 'org.springframework.boot' version '2.4.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'com.github.johnrengelman.shadow' version '6.1.0'
}
group = 'com.lipsum'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
jar {
manifest {
attributes('Main-Class': 'com.lipsum.kafkastream.KafkastreamApplication')
}
}
shadowJar {
archiveBaseName.set('kafka-stream-practice')
archiveClassifier.set('')
archiveVersion.set('')
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2020.0.2")
}
dependencies {
implementation 'org.apache.kafka:kafka-streams'
implementation 'org.springframework.cloud:spring-cloud-stream'
implementation 'org.springframework.cloud:spring-cloud-stream-binder-kafka-streams'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
I execute the uber jar, but springboot application fails to recognize the bean.
$ java -jar kafka-stream-practice.jar --spring.cloud.stream.bindings.process-in-0.destination=kafka-stream-practice
...
22:47:21.162 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'kafkaStreamsFunctionProcessorInvoker' defined in class path resource [org/springframework/cloud/stream/binder/kafka/streams/function/KafkaStreamsFunctionAutoConfiguration.class]: Unsatisfied dependency expressed through method 'kafkaStreamsFunctionProcessorInvoker' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.stream.binder.kafka.streams.KafkaStreamsFunctionProcessor' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.stream.binder.kafka.streams.KafkaStreamsFunctionProcessor' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
I don't think the implementation has any problems. Do I miss some dependencies?
I tried a quick maven project from the initialize and it starts fine. There was a known bug on the last release (3.0.11) which was fixed since then on the snapshot. You can fix the issue by adding the boot actuator dependency to the project or by upgrading the binder to the latest snapshot. Could you try the maven approach? If the problem still persists, please share a reproducible sample, and then we will take a look.
It works after removing shadowJar and instead uses bootJar task of Spring Boot Gradle plugin.

failed to build spingboot with swagger 2.0

I am relatively new to spring. I tried to add API documentation with Swagger-2.0 and I no longer able to build
I failed to build with "gradlew build"
> getProductById FAILED
java.lang.IllegalStateException
Caused by: org.springframework.context.ApplicationContextException
Caused by: java.lang.NoSuchMethodError
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: 'org.springframework.plugin.core.Plugin org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor(java.lang.Object, org.springframework.plugin.core.Plugin)'
Caused by: java.lang.NoSuchMethodError: 'org.springframework.plugin.core.Plugin org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor(java.lang.Object, org.springframework.plugin.core.Plugin)'
In build.gradle I added :
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
dependencies {
implementation project(':api')
implementation project(':util')
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-webflux')
implementation('io.springfox:springfox-swagger2:3.0.0-SNAPSHOT')
implementation('io.springfox:springfox-swagger-ui:3.0.0-SNAPSHOT')
implementation('io.springfox:springfox-spring-webflux:3.0.0-SNAPSHOT')
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('io.projectreactor:reactor-test')
}
Where should I look to find the root cause ?

Spring boot Eureka server project not starting

I just created Spring Boot project(with Gradle Buildship 3.x) and I enabled Eurekaserver on main class.I am getting following error
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'traceFilterRegistration' defined in class path resource [org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]: Unsatisfied dependency expressed through method 'traceFilterRegistration' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.servlet.Filter' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Qualifier(value=httpTraceFilter)}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:539) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-web')
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-server', version: '2.0.1.RELEASE'
}
test {
useJUnitPlatform()
}
application.properties:
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
Issue that you encounter has been fix already, at May 13 2019, issue
spring-cloud-netflix
Though issue has been resolved over a year ago I encounter it lately. For reference, as workaround, you can add missing bean. It will be created only if not provided by spring cloud netfix:
#ConditionalOnMissingBean
#Bean
public HttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}

Resources