In my machine (Windows 10), there are two versions of Java, Java 1.8 (JRE and JDK) and Java 10 (JRE and JDK).
Previously IF I set my Eclipse to:
THEN IF i use following Spring code
import javax.annotation.PostConstruct;
...
...
...
@PostConstruct
...
...
Everything works fine. No error at all.
However, IF I set my Eclipse to:
Now, the import
statement is throwing an Error message:
The import javax.annotation.PostConstruct cannot be resolved
and this error also happen on @PreDestroy
annotation too.
Why is this happening? What happen to Java 10? How to solve this problem if i still want to retain Java Compiler and JRE System Libraries version to Java 10?
Thank You.
You can try to add annotation dependencies to pom.xml, so that they would be available for Spring:
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
You would need to point the Eclipse to Java 8 via Window -->Preferences-->Java and add JDK 1.8 bin path. Once done, project will be built automatically and issue should be resolved.
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