Reputation: 424
I was just going through spring documentation for Lifecycle callbacks for a bean. For initialization callback the documentation recommends using @PostConstruct annotation instead of using the InitializingBean interface implementation as it couples code with Spring. Could someone please explain what they mean when they say coupling code with spring. I will share the link to the section i was going through here.
Upvotes: 1
Views: 157
Reputation: 10218
The @PostContruct
annotation is not Spring-specific, but from Jakarta Annotations. This way, the core part of your code is not tied to Spring specifically, but could also work in a non-Spring environment, including any Jakarta EE implementation (see "Certified referencing runtimes" in the article), for example, GlassFish or WildFly.
Here is the relevant Javadoc from the Jakarta documentation: PostConstruct.
Upvotes: 1
Reputation: 5420
InitializingBean
is pure Spring and will only work in Spring. @PostConstruct
is ordinary Java 1.8. Sadly, from 9 it's dependent on javax.annotation:javax.annotation-api:1.3.2
Upvotes: 0