When i import the following packages
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
i got the follwing resulat - The import javax.annotation.PostConstruct cannot be resolved
When we annotate a method in Spring Bean with @PostConstruct annotation, it gets executed after the spring bean is initialized. We can have only one method annotated with @PostConstruct annotation. This annotation is part of Common Annotations API and it's part of JDK module javax.
The two possible authentication types for a resource. The Generated annotation is used to mark source code that has been generated. The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization.
If a PostConstruct interceptor method returns a value, it is ignored by the container. The method on which PostConstruct is applied MAY be public, protected, package private or private. The method MUST NOT be static except for the application client. The method MAY be final.
In jdk9 @PostConstruct and @PreDestroy are in java. xml. ws. annotation which is deprecated and scheduled for removal.
If you are using spring-boot and below dependency then it should add javax.annotation
automatically from parent starter.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
For non spring boot starter data jpa add below dependency in pom.xml
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With