I am updating my @SpringBootApplication
application from Spring Boot 1.5 to 2.2 and Spring 4.3 to 5.2 and I am having issues with a custom @Profile
annotations.
In the older version, I had annotation
@Profile("sapConnector")
public @interface SapConnectorProfile {
}
and every bean that belongs to "sapConnector" was annotated with the @SapConnectorProfile
annotation. When I was running the application I simply defined property spring.profiles.active=sapConnector
and it loads the beans annotated with this annotation. And if I changed the property to f.e. spring.profiles.active=demoConnector
it does not load any bean with @SapConnectorProfile
annotation.
In the new version of Spring, all beans annotated with @SapConnectorProfile
are loaded even if the property spring.profiles.active=demoConnector
.
It is not possible to do this anymore in the new Spring?
The profiles work fine if I use annotation @Profile("sapConnector")
instead of @SapConnectorProfile
.
Thank you for help.
I was missing @Retention(RetentionPolicy.RUNTIME)
annotation.
Everything works fine when I use:
@Retention(RetentionPolicy.RUNTIME)
@Profile("sapConnector")
public @interface SapConnectorProfile {
}
Issue I have created: https://github.com/spring-projects/spring-framework/issues/23901