Hi,
I've created a Spring project, and created a bean and added lifecycle method annotated with PostConstruct. According to the specification, read here: https://docs.spring.io/spring-framework/reference/core/beans/annotation-config/postconstruct-and-predestroy-annotations.html I added jakarta.annotation-api dependency and imported the PostConstruct annotation. The method annotated by PostConstruct was not called by Spring framework. After some investigation I found in other source (https://www.baeldung.com/spring-postconstruct-predestroy#java-9) that the dependency should be javax.annotation-api.
Spring version: 5.3.31 Java version: 17.0.7 maven version: 3.9.0
If my observation is correct, please fix the documentation and replace jakarta.annotation-api dependency with javax.annotation-api.
If you need any more details about the issue, please let me know.
Thanks, Viktor Selmeci developer
Comment From: bclozel
The documentation link you're pointing to is using Spring Framework 6.x which requires jakarta annotations. With Spring Framework 5.3.x only javax.*
annotations work since this predates the jakarta variant; please refer to the documentation for the version you are using.
I'm closing this issue as this works as expected.