web-dev-qa-db-fra.com

import javax.annotation. * ne peut pas être résolu dans le compilateur Eclipse Java 10

Dans ma machine (Windows 10), il existe deux versions de Java, Java 1.8 (JRE et JDK) et Java 10 (JRE et JDK).

Auparavant SI J'ai défini mon Eclipse sur:

  • Compilateur Java (compatibilité JDK) : 1.8
  • Chemin de génération Java (bibliothèques système JRE) : 1.8

ALORS SI j'utilise le code Spring suivant

import javax.annotation.PostConstruct;
...
...
...
@PostConstruct
...
...

Tout fonctionne bien. Aucune erreur.

Cependant, SI je règle mon Eclipse sur:

  • Compilateur Java (compatibilité JDK) : 1
  • Chemin de génération Java (bibliothèques système JRE) : 1

Maintenant, l'instruction import est lançant un message d'erreur:

The import javax.annotation.PostConstruct cannot be resolved

et cela ne erreur se produit également le @PreDestroy annotation aussi.

Pourquoi cela arrive-t-il? Qu'arrive-t-il à Java 10? Comment résoudre ce problème si je veux toujours conserver Java Compilateur et version des bibliothèques système JRE à Java 10?

Merci.

7
xcode

Vous pouvez essayer d'ajouter des dépendances d'annotation à pom.xml, afin qu'elles soient disponibles pour Spring:

<dependency>
  <groupId>javax.annotation</groupId>
  <artifactId>javax.annotation-api</artifactId>
  <version>1.3.2</version>
</dependency>
12
Anna van den Akker