Spring application failed to start with enabled LoadTime weaving - java

Good day everyone!
I have a spring boot web application for which I have added Load time weaving to be able to use AspectJ aspects for non-managed spring bean, but after that application failed to start. I have looked through many topics regarding the configuration of load time weaving for non-spring beans in the spring project but haven't met if anyone has faced the issue I currently have.
My configuration:
gradle dependencies:
dependencies {
compileOnly ("org.projectlombok:lombok:${lombokVersion}")
implementation("org.aspectj:aspectjweaver:1.9.9.1")
implementation ("org.mapstruct:mapstruct:${mapstructVersion}")
implementation("com.fasterxml.jackson.core:jackson-databind:2.14.0-rc1")
implementation ("mysql:mysql-connector-java:8.0.30")
implementation("org.opensearch.client:opensearch-java:2.1.0")
implementation("software.amazon.awssdk:apache-client:${awsSdkVersion}")
implementation("software.amazon.awssdk:regions:${awsSdkVersion}")
implementation("software.amazon.awssdk:auth:${awsSdkVersion}")
implementation("jakarta.json:jakarta.json-api:2.1.1")
implementation("commons-io:commons-io:2.11.0")
implementation ("org.springframework.boot:spring-boot-starter-web")
implementation ("org.springframework.boot:spring-boot-starter-data-jpa")
implementation ("org.springframework.boot:spring-boot-starter-security")
implementation ("org.springframework.boot:spring-boot-starter-validation")
implementation ("org.springframework.boot:spring-boot-starter-log4j2")
annotationProcessor ("org.projectlombok:lombok-mapstruct-binding:0.2.0")
annotationProcessor ("org.mapstruct:mapstruct-processor:${mapstructVersion}")
annotationProcessor ("org.projectlombok:lombok:${lombokVersion}")
testImplementation("org.testcontainers:mysql:1.17.5")
testImplementation ("org.springframework.boot:spring-boot-starter-test")
testImplementation("com.h2database:h2:2.1.214")
testCompileOnly("org.projectlombok:lombok:${lombokVersion}")
testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")
}
The spring boot versions are:
springBootVersion=2.7.4
dependencyManagement=1.0.14.RELEASE
Main application class:
#SuppressWarnings({"checkstyle:FinalClass", "checkstyle:HideUtilityClassConstructor"})
#SpringBootApplication
#EnableGlobalMethodSecurity(securedEnabled = true)
#EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
#EnableCaching
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(WhiteCoatApp.class, args);
}
}
Aspect:
#Aspect
public class DefaultViewsReturnHandler {
#Around("viewObjects()")
public Object handle(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("Do something");
return joinPoint.proceed();
}
#Pointcut("execution(* com.project.TestTest.getTestString(..))")
public void viewObjects() {}
}
Configuration of META-INF/aop.xml
<aspectj>
<aspects>
<aspect name="com.project.common.DefaultViewsReturnHandler"/>
</aspects>
<weaver options="-verbose -showWeaveInfo">
<include within="com.project..*"/>
</weaver>
</aspectj>
And the class itself i would like to apply the aspect to is the simple pojo
public class TestTest {
private String testString;
public String getTestString() {
return "myString";
}
}
I'm running the application with
-javaagent:libs/spring-instrument-6.0.0.jar
and java 17
But had the error:
[INFO ] 2022-11-17 18:49:51.009 [background-preinit] Version - HV000001: Hibernate Validator 6.2.5.Final
[INFO ] 2022-11-17 18:49:51.326 [main] RepositoryConfigurationDelegate - Bootstrapping Spring Data JPA repositories in DEFAULT mode.
[INFO ] 2022-11-17 18:49:51.359 [main] RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 29 ms. Found 2 JPA repository interfaces.
[ERROR] 2022-11-17 18:49:51.454 [main] SpringApplication - Application run failed
java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) accessible: module java.base does not "opens java.lang" to unnamed module #5dda768f
at java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[?:?]
at java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[?:?]
at java.lang.reflect.Method.checkCanSetAccessible(Method.java:199) ~[?:?]
at java.lang.reflect.Method.setAccessible(Method.java:193) ~[?:?]
at org.springframework.util.ReflectionUtils.makeAccessible(ReflectionUtils.java:577) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.context.support.ContextTypeMatchClassLoader$ContextOverridingClassLoader.isEligibleForOverriding(ContextTypeMatchClassLoader.java:99) ~[spring-context-5.3.23.jar:5.3.23]
at org.springframework.core.OverridingClassLoader.loadClass(OverridingClassLoader.java:87) ~[spring-core-5.3.23.jar:5.3.23]
at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
at org.springframework.core.OverridingClassLoader.loadClass(OverridingClassLoader.java:82) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.context.support.ContextTypeMatchClassLoader.loadClass(ContextTypeMatchClassLoader.java:70) ~[spring-context-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1594) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1534) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:704) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:674) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1670) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:221) ~[spring-context-5.3.23.jar:5.3.23]
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762) ~[spring-context-5.3.23.jar:5.3.23]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567) ~[spring-context-5.3.23.jar:5.3.23]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.4.jar:2.7.4]
at com.piecestech.whitecoat.platform.WhiteCoatApp.main(WhiteCoatApp.java:20) ~[main/:?]
[WARN ] 2022-11-17 18:49:51.465 [main] SpringApplication - Unable to close ApplicationContext
java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) accessible: module java.base does not "opens java.lang" to unnamed module #5dda768f
at java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[?:?]
at java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[?:?]
at java.lang.reflect.Method.checkCanSetAccessible(Method.java:199) ~[?:?]
at java.lang.reflect.Method.setAccessible(Method.java:193) ~[?:?]
at org.springframework.util.ReflectionUtils.makeAccessible(ReflectionUtils.java:577) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.context.support.ContextTypeMatchClassLoader$ContextOverridingClassLoader.isEligibleForOverriding(ContextTypeMatchClassLoader.java:99) ~[spring-context-5.3.23.jar:5.3.23]
at org.springframework.core.OverridingClassLoader.loadClass(OverridingClassLoader.java:87) ~[spring-core-5.3.23.jar:5.3.23]
at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
at org.springframework.core.OverridingClassLoader.loadClass(OverridingClassLoader.java:82) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.context.support.ContextTypeMatchClassLoader.loadClass(ContextTypeMatchClassLoader.java:70) ~[spring-context-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1594) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1534) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:704) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:674) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1670) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:669) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:661) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1300) ~[spring-context-5.3.23.jar:5.3.23]
at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:867) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:855) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:842) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:782) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.4.jar:2.7.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.4.jar:2.7.4]
at com.piecestech.whitecoat.platform.WhiteCoatApp.main(WhiteCoatApp.java:20) ~[main/:?]
Will appreciate any thoughts on this!

In the AspectJ release notes you can read the following:
Use LTW on Java 16+
Please note that if you want to use load-time weaving on Java 16+, the weaving agent collides with JEP 396 (Strongly Encapsulate JDK Internals by Default) and related subsequent JEPs. Therefore, you need to set the JVM parameter --add-opens java.base/java.lang=ALL-UNNAMED in order to enable aspect weaving. This is due to the fact that the weaver uses internal APIs for which we have not found an adequate replacement yet when defining classes in different classloaders.

Related

#Value annotation does not pick properties from GIT URL in spring cloud config server

I am working on a spring boot upgrade project where i am upgrading spring boot version 2.2.7.RELEASE to Spring boot 2.6.7 and also upgrading spring cloud config server to 2021.0.2. In my config server, I am using #Value annotation to pick property from GIT URL.
spring.cloud.config.server.git.uri=https://phabric.xyz.com/configuration/settings/applicationconfig/application-config.git
spring.cloud.config.server.git.searchPaths={application}
spring.cloud.config.server.git.username=testbot
spring.cloud.config.server.git.password=testpass
and used the default-label to my feature branch.
spring.cloud.config.server.git.default-label=springboot
When I start the application, system throws following exception.
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'monitoring.amq.server.url' in value "${monitoring.amq.server.url}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180) ~[spring-core-5.3.10.jar:5.3.10]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-5.3.10.jar:5.3.10]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239) ~[spring-core-5.3.10.jar:5.3.10]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-5.3.10.jar:5.3.10]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:936) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1321) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:657) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.10.jar:5.3.10]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.10.jar:5.3.10]
... 32 common frames omitted
If I add monitoring.amq.server.url into my application.properties file it is working without any error.
Your help is really appreciated.

Application won't start as MongoOperations bean is not defined

I'm working through the book Learning Spring Boot 2.0, Second Edition but using Spring Boot 2.5.6 so I suspect my issue might be related to me having to do things slightly with the different version.
I have this class:
#Component
public class InitDatabase {
#Bean
CommandLineRunner init(MongoOperations operations) {
return args -> {
operations.dropCollection(Image.class);
operations.insert(new Image("1", "learning-spring-boot-cover.jpg"));
operations.insert(new Image("2", "learning-spring-boot-2nd-edition-cover.jpg"));
operations.insert(new Image("3", "bazinga.png"));
operations.findAll(Image.class).forEach(image -> System.out.println(image.toString()));
};
}
}
When I run my application I get this error:
2021-11-25 12:26:42.870 DEBUG 71010 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : Application failed to start due to an exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.data.mongodb.core.MongoOperations' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1790) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1346) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.12.jar:5.3.12]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.12.jar:5.3.12]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.12.jar:5.3.12]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:64) ~[spring-boot-2.5.6.jar:2.5.6]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.6.jar:2.5.6]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.6.jar:2.5.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.6.jar:2.5.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.6.jar:2.5.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.6.jar:2.5.6]
at com.paulcarron.learningspringboot.learningspringboot.LearningSpringBootApplication.main(LearningSpringBootApplication.java:12) ~[classes/:na]
2021-11-25 12:26:42.870 ERROR 71010 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
Parameter 0 of method init in com.paulcarron.learningspringboot.learningspringboot.InitDatabase required a bean of type 'org.springframework.data.mongodb.core.MongoOperations' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.data.mongodb.core.MongoOperations' in your configuration.
This is my build.gradle:
plugins {
id 'org.springframework.boot' version '2.5.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.paulcarron.learningspringboot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.synchronoss.cloud:nio-multipart-parser:1.1.0'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'javax.persistence:javax.persistence-api:2.2'
}
test {
useJUnitPlatform()
}
My understanding is that I don't need to activate the with #EnableReactiveMongoRepositories as this is done automatically if Reactive MongoDB or Spring DataMongoDB 2.0+ are on the classpath.
Is there any obvious reason why this is not working?
I guess you're trying to init your database on the startup.
You can leverage the spring internal event mechanism.
When your application is ready, spring triggers the event ApplicationReadyEvent
You can listen to this event and init your collection:
#Component
public class DataInit implements ApplicationListener<ApplicationReadyEvent> {
private final MongoOperations operations;
public DataInit(MongoOperations operations) {
this.operations = operations;
}
#Override
public void onApplicationEvent(ApplicationReadyEvent event) {
// init data
}
}
If you want to know more about spring events --> https://www.baeldung.com/spring-events
MongoOperations is the interface for interacting with Mongo in a blocking manner. ReactiveMongoOperations is the interface for interacting with Mongo in a reactive manner.
As you're using WebFlux (spring-boot-starter-webflux), it would appear that you want to build a reactive application. If so, you should replace your use of MongoOperations with ReactiveMongoOperations. The, if you want to build a blocking, Servlet-based web application would be to switch to spring-boot-starter-data-mongodb and spring-boot-starter-web.
I want to preload data and read that it was best to do this using a blocking API because when launching an application there is a risk of a thread lock issue when both the web container and my loader are starting up. The book I'm using is for an older veriosn of both Spring Boot and MongoDB.
It seems that the version of spring-boot-starter-data-mongodb-reactive that the book used contained MongoOperations but this was then split out. See this.
To use this I added implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' to my class path.
If there wasn't the issue of thread lock I could have used ReactiveMongoOperations instead.

Unable to start my application after upgrading Spring jars

I have updated the following spring dependencies in my project pom.xml
From:
<spring.version>5.3.6</spring.version>
<spring.security.version>5.4.4</spring.security.version>
<spring.boot.version>2.3.10.RELEASE</spring.boot.version>
To:
<spring.version>5.3.8</spring.version>
<spring.security.version>5.5.1</spring.security.version
<spring.boot.version>2.5.2</spring.boot.version>
I was able to build my project successfully whereas, when I tried to start my application, I see the following error and my application fails to start at all.
Can any one help me with the resolution.
Caused by: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine superclass of missing type org.springframework.boot.validation.beanvalidation.MethodValidationExcludeFilter$$Lambda$819.0x000000080096f440
[Xlint:cantFindType]
at org.aspectj.weaver.reflect.ReflectionWorld$ExceptionBasedMessageHandler.handleMessage(ReflectionWorld.java:217) ~[aspectjweaver-1.9.7.jar!/:?]
at org.aspectj.weaver.Lint$Kind.signal(Lint.java:339) ~[aspectjweaver-1.9.7.jar!/:1.9.7]
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.raiseCantFindType(MissingResolvedTypeWithKnownSignature.java:237) ~[aspectjweaver-1.9.7.jar!/:1.9.7]
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.getSuperclass(MissingResolvedTypeWithKnownSignature.java:98) ~[aspectjweaver-1.9.7.jar!/:1.9.7]
at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95) ~[aspectjweaver-1.9.7.jar!/:1.9.7]
at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49) ~[aspectjweaver-1.9.7.jar!/:1.9.7]
at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515) ~[aspectjweaver-1.9.7.jar!/:1.9.7]
at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:316) ~[aspectjweaver-1.9.7.jar!/:?]
at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:202) ~[aspectjweaver-1.9.7.jar!/:?]
at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137) ~[aspectjweaver-1.9.7.jar!/:?]
at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319) ~[aspectjweaver-1.9.7.jar!/:?]
at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129) ~[aspectjweaver-1.9.7.jar!/:?]
at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110) ~[aspectjweaver-1.9.7.jar!/:?]
at org.springframework.security.config.method.ProtectPointcutPostProcessor.attemptMatch(ProtectPointcutPostProcessor.java:148) ~[spring-security-config-5.5.1.jar!/:5.5.1]
at org.springframework.security.config.method.ProtectPointcutPostProcessor.postProcessBeforeInitialization(ProtectPointcutPostProcessor.java:125) ~[spring-security-config-5.5.1.jar!/:5.5.1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:422) ~[spring-beans-5.3.8.jar!/:5.3.8]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.3.8.jar!/:5.3.8]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.8.jar!/:5.3.8]
... 23 more
Warning!
This is not Production Grade solution but this may be considered as starting point for further investigation.
Background
We have quite legacy (~10yo) application and we currently run into same issue during Spring Boot upgrade from 2.3.9 to 2.4.0 (Full stack below).
It seems to me that problem is related to three issues:
ProtectPointcutPostProcessor - from spring security
MethodValidationPostProcessor - which lack of disables the error
change in Spring Boot 2.4.0 - which is described below
Possible cause description
In Spring Boot 2.4.0 new Bean has been introduced in EnableConfigurationPropertiesRegistrar:
static void registerMethodValidationExcludeFilter(BeanDefinitionRegistry registry) {
if (!registry.containsBeanDefinition(METHOD_VALIDATION_EXCLUDE_FILTER_BEAN_NAME)) {
BeanDefinition definition = BeanDefinitionBuilder
.genericBeanDefinition(MethodValidationExcludeFilter.class,
() -> MethodValidationExcludeFilter.byAnnotation(ConfigurationProperties.class))
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE).getBeanDefinition();
registry.registerBeanDefinition(METHOD_VALIDATION_EXCLUDE_FILTER_BEAN_NAME, definition);
}
}
This bean is generated with MethodValidationExcludeFilter.byAnnotation as Lambda:
static MethodValidationExcludeFilter byAnnotation(Class<? extends Annotation> annotationType,
SearchStrategy searchStrategy) {
return (type) -> MergedAnnotations.from(type, SearchStrategy.SUPERCLASS).isPresent(annotationType);
}
Because of being Lambda it has no parent class and fails miserably on bean creation post processing.
(Very) hacky solution
Luckily EnableConfigurationPropertiesRegistrar.registerMethodValidationExcludeFilter contains if statement which checks if bean has not been created. So we may create this bean manually instead:
#Bean("org.springframework.boot.context.properties.EnableConfigurationPropertiesRegistrar.methodValidationExcludeFilter")
public MethodValidationExcludeFilter mockMethodValidationExcludeFilter() {​​​​​​​​
return new MethodValidationExcludeFilter() {​​​​​​​​
#Override
public boolean isExcluded( Class< ? > type ) {​​​​​​​​
return MethodValidationExcludeFilter.byAnnotation( ConfigurationProperties.class).isExcluded( type );
}​​​​​​​​
}​​​​​​​​;
}​​​​​​​​
Or even as:
#Bean("org.springframework.boot.context.properties.EnableConfigurationPropertiesRegistrar.methodValidationExcludeFilter")
public String mockMethodValidationExcludeFilter() {
return "mockMethodValidationExcludeFilter";
}
But this seems to me as very dirty hack and not suitable for production usage.
Theoretically disabling linting error cantFindType could also save the day as doing it on debug has allowed application to run but
we have not achieved proper configuration to disable it
this seems as dirty hack as well and should be considered as last resort and not proper solution
Logs
Full error stack trace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.context.properties.EnableConfigurationPropertiesRegistrar.methodValidationExcludeFilter' defined in class path resource [com/source/etf/common/aop/AopConfig.class]: Initialization of bean failed; nested exception is org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine superclass of missing type com.source.etf.common.aop.AopConfig$$Lambda$751.0x00000008008fec40
[Xlint:cantFindType]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:617) ~[spring-beans-5.3.1.jar:5.3.1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar:5.3.1]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar:5.3.1]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar:5.3.1]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar:5.3.1]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.1.jar:5.3.1]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.1.jar:5.3.1]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925) ~[spring-context-5.3.1.jar:5.3.1]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:588) ~[spring-context-5.3.1.jar:5.3.1]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.0.jar:2.4.0]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.0.jar:2.4.0]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.0.jar:2.4.0]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.0.jar:2.4.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.0.jar:2.4.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309) ~[spring-boot-2.4.0.jar:2.4.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298) ~[spring-boot-2.4.0.jar:2.4.0]
at com.source.etf.EtfmApplication.main(EtfmApplication.java:56) ~[main/:na]
Caused by: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine superclass of missing type com.source.etf.common.aop.AopConfig$$Lambda$751.0x00000008008fec40
[Xlint:cantFindType]
at org.aspectj.weaver.reflect.ReflectionWorld$ExceptionBasedMessageHandler.handleMessage(ReflectionWorld.java:219) ~[aspectjweaver-1.9.6.jar:na]
at org.aspectj.weaver.Lint$Kind.signal(Lint.java:340) ~[aspectjweaver-1.9.6.jar:1.9.6]
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.raiseCantFindType(MissingResolvedTypeWithKnownSignature.java:237) ~[aspectjweaver-1.9.6.jar:1.9.6]
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.getSuperclass(MissingResolvedTypeWithKnownSignature.java:98) ~[aspectjweaver-1.9.6.jar:1.9.6]
at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95) ~[aspectjweaver-1.9.6.jar:1.9.6]
at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49) ~[aspectjweaver-1.9.6.jar:1.9.6]
at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515) ~[aspectjweaver-1.9.6.jar:1.9.6]
at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:319) ~[aspectjweaver-1.9.6.jar:na]
at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:202) ~[aspectjweaver-1.9.6.jar:na]
at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137) ~[aspectjweaver-1.9.6.jar:na]
at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319) ~[aspectjweaver-1.9.6.jar:na]
at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129) ~[aspectjweaver-1.9.6.jar:na]
at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110) ~[aspectjweaver-1.9.6.jar:na]
at org.springframework.security.config.method.ProtectPointcutPostProcessor.attemptMatch(ProtectPointcutPostProcessor.java:148) ~[spring-security-config-5.4.5.jar:5.4.5]
at org.springframework.security.config.method.ProtectPointcutPostProcessor.postProcessBeforeInitialization(ProtectPointcutPostProcessor.java:125) ~[spring-security-config-5.4.5.jar:5.4.5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:429) ~[spring-beans-5.3.1.jar:5.3.1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1780) ~[spring-beans-5.3.1.jar:5.3.1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-5.3.1.jar:5.3.1]
... 16 common frames omitted
Process finished with exit code 1

Spring Cloud Kafka and AWS Secrets 'inputBindingLifecycle' exception

I am trying to integrate our spring cloud kafka apps with aws secrets on spring boot 2.4 and Spring cloud 2020.0.1
Here is my test code:
#SpringBootApplication
public class DemoApplication {
#Value(value = "${secret-property}")
private String awsSecretProperty;
// Test AWS Secrets
#PostConstruct
public void testProp() {
System.out.println("AWS Secret Property: " + awsSecretProperty);
}
// Test Kafka
#Bean
public Consumer<String> sink() {
return message -> {
System.out.println("Message: " + message);
};
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
My properties are:
spring.application.name=test-kafka-aws-secrets
spring.config.import=aws-secretsmanager:test-secret
aws.secretsmanager.enabled=true
spring.cloud.function.definition=sink
spring.cloud.stream.default-binder=kafka
spring.kafka.consumer.key-deserializer=io.confluent.kafka.serializers.KafkaAvroDeserializer
spring.kafka.consumer.value-deserializer=io.confluent.kafka.serializers.KafkaAvroDeserializer
spring.cloud.stream.bindings.sink-in-0.destination=test-topic
spring.cloud.stream.bindings.sink-in-0.group=${spring.application.name}
spring.cloud.stream.kafka.bindings.sink-in-0.consumer.startOffset=earliest
spring.cloud.stream.bindings.sink-in-0.content-type=application/*+avro
spring.cloud.stream.bindings.sink-in-0.consumer.use-native-decoding=true
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.properties.schema.registry.url=http://localhost:8081
I have these two dependencies in my pom:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-kafka</artifactId>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-starter-aws-secrets-manager-config</artifactId>
<version>2.3.0-RC2</version>
</dependency>
I get the following exception when I run the above code:
org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle'; nested exception is java.lang.IllegalStateException: Could not register object [com.amazonaws.services.secretsmanager.AWSSecretsManagerClient#388be5fd] under bean name 'configDataAWSSecretsManager': there is already object [com.amazonaws.services.secretsmanager.AWSSecretsManagerClient#388be5fd] bound
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.4.jar:5.3.4]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:934) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:585) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.4.3.jar:2.4.3]
at com.example.demo.DemoApplication.main(DemoApplication.java:31) ~[classes/:na]
Caused by: java.lang.IllegalStateException: Could not register object [com.amazonaws.services.secretsmanager.AWSSecretsManagerClient#388be5fd] under bean name 'configDataAWSSecretsManager': there is already object [com.amazonaws.services.secretsmanager.AWSSecretsManagerClient#388be5fd] bound
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.registerSingleton(DefaultSingletonBeanRegistry.java:124) ~[spring-beans-5.3.4.jar:5.3.4]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerSingleton(DefaultListableBeanFactory.java:1138) ~[spring-beans-5.3.4.jar:5.3.4]
at io.awspring.cloud.autoconfigure.secretsmanager.AwsSecretsManagerConfigDataLocationResolver.lambda$registerAndPromoteBean$1(AwsSecretsManagerConfigDataLocationResolver.java:113) ~[spring-cloud-starter-aws-secrets-manager-config-2.3.0-RC2.jar:2.3.0-RC2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.boot.DefaultBootstrapContext.close(DefaultBootstrapContext.java:133) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:392) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:325) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:144) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.cloud.stream.binder.DefaultBinderFactory.getBinderInstance(DefaultBinderFactory.java:326) ~[spring-cloud-stream-3.1.1.jar:3.1.1]
at org.springframework.cloud.stream.binder.DefaultBinderFactory.doGetBinder(DefaultBinderFactory.java:215) ~[spring-cloud-stream-3.1.1.jar:3.1.1]
at org.springframework.cloud.stream.binder.DefaultBinderFactory.getBinder(DefaultBinderFactory.java:143) ~[spring-cloud-stream-3.1.1.jar:3.1.1]
at org.springframework.cloud.stream.binding.BindingService.getBinder(BindingService.java:379) ~[spring-cloud-stream-3.1.1.jar:3.1.1]
at org.springframework.cloud.stream.binding.BindingService.bindConsumer(BindingService.java:102) ~[spring-cloud-stream-3.1.1.jar:3.1.1]
at org.springframework.cloud.stream.binding.AbstractBindableProxyFactory.createAndBindInputs(AbstractBindableProxyFactory.java:112) ~[spring-cloud-stream-3.1.1.jar:3.1.1]
at org.springframework.cloud.stream.binding.InputBindingLifecycle.doStartWithBindable(InputBindingLifecycle.java:58) ~[spring-cloud-stream-3.1.1.jar:3.1.1]
at java.base/java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:608) ~[na:na]
at org.springframework.cloud.stream.binding.AbstractBindingLifecycle.start(AbstractBindingLifecycle.java:57) ~[spring-cloud-stream-3.1.1.jar:3.1.1]
at org.springframework.cloud.stream.binding.InputBindingLifecycle.start(InputBindingLifecycle.java:34) ~[spring-cloud-stream-3.1.1.jar:3.1.1]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.4.jar:5.3.4]
... 14 common frames omitted
My whole code is essentially above. Any idea how I could resolve this error?
Thank you!
It would be useful to see the full exception stack trace. Based on the first line of the stack trace you've provided to date, an IllegalStateException with the same cause as the one you've mentioned is thrown when the Spring Boot (2.4) app configuration defines the spring.config.import property (with the same prefix, in this case "aws-secretsmanager:") more than once, in different property sources. For example for a Spring Boot 2.4 on application startup -
:: Spring Boot :: (v2.4.2)
2021-02-25 21:18:33.155 INFO 88284 --- [ main] o.s.b.c.c.ConfigDataLocationResolver : Loading secrets from AWS Secret Manager secret with name: /my-secret, optional: false
2021-02-25 21:18:33.192 ERROR 88284 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Could not register object [com.amazonaws.services.secretsmanager.AWSSecretsManagerClient#4d21c56e] under bean name 'configDataAWSSecretsManager': there is already object [com.amazonaws.services.secretsmanager.AWSSecretsManagerClient#4d21c56e] bound
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.registerSingleton(DefaultSingletonBeanRegistry.java:124) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerSingleton(DefaultListableBeanFactory.java:1138) ~[spring-beans-5.3.3.jar:5.3.3]
at io.awspring.cloud.autoconfigure.secretsmanager.AwsSecretsManagerConfigDataLocationResolver.lambda$registerAndPromoteBean$1(AwsSecretsManagerConfigDataLocationResolver.java:113) ~[spring-cloud-starter-aws-secrets-manager-config-2.3.0-RC2.jar:2.3.0-RC2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.3.jar:5.3.3]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.3.jar:5.3.3]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.3.jar:5.3.3]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) ~[spring-context-5.3.3.jar:5.3.3]
at org.springframework.boot.DefaultBootstrapContext.close(DefaultBootstrapContext.java:133) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:392) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:325) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) ~[spring-boot-2.4.2.jar:2.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.4.2.jar:2.4.2]
at com.brighttalk.service.securedsecrets.Application.main(Application.java:43) ~[main/:na]
The example code you've provided above suggests this is not the case (its a single properties file with one definition of this property). But you might want to double-check your code is not loading properties from another source also. Regards.

Unix Domain Socket configuration in Spring Boot Webflux

Spring Boot version: 2.4.0Reactor netty now supports Unix Domain Sockets while initializing server.
I am trying to custmoize Spring Boot HttpServer to use unix domain socket instead of http port using
#Configuration
public class NettyConfig {
#Bean
public NettyReactiveWebServerFactory factory() {
NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();
factory.setServerCustomizers(Collections.singletonList(new NettyServerCustomizer() {
#Override
public HttpServer apply(HttpServer httpServer) {
return httpServer.bindAddress(() -> new DomainSocketAddress("/tmp/test.sock"));
}
}));
return factory;
}
}
But application is unable to start with given stacktrace:
13:05:36.706 ERROR [restartedMain] SpringApplication.reportFailure:856 : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is java.lang.UnsupportedOperationException
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:942)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:591)
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:63)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
at com.avis.biverve.EntryPoint.main(EntryPoint.java:25)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.UnsupportedOperationException
at reactor.netty.DisposableServer.port(DisposableServer.java:69)
at org.springframework.boot.web.embedded.netty.NettyWebServer.getPort(NettyWebServer.java:193)
at org.springframework.boot.web.embedded.netty.NettyWebServer.start(NettyWebServer.java:109)
at org.springframework.boot.web.reactive.context.WebServerManager.start(WebServerManager.java:54)
at org.springframework.boot.web.reactive.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:40)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
... 20 more
This issue is fixed in Spring Boot version 2.4.2
https://github.com/spring-projects/spring-boot/issues/24529

Categories

Resources