导入javax.annotation。*无法在Eclipse的Java 10编译器中解析 [英] import javax.annotation.* cannot be resolved in Eclipse's Java 10 Compiler

查看:2110
本文介绍了导入javax.annotation。*无法在Eclipse的Java 10编译器中解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的机器(Windows 10)中,有两个版本的Java,Java 1.8(JRE和JDK)和Java 10(JRE和JDK)。

In my machine (Windows 10), there are two versions of Java, Java 1.8 (JRE and JDK) and Java 10 (JRE and JDK).

以前 IF 我将 Eclipse 设置为:


  • Java编译器(JDK Complience):1.8

  • Java构建路径(JRE系统库):1.8

  • Java Compiler (JDK Complience) : 1.8
  • Java Build Path (JRE System Libraries) : 1.8

那么我使用以下Spring代码

THEN IF i use following Spring code

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

一切正常很好。完全没有错误。

Everything works fine. No error at all.

但是,如果我将Eclipse设置为:

However, IF I set my Eclipse to:


  • Java编译器(JDK Complience):10

  • Java构建路径(JRE系统库):10

  • Java Compiler (JDK Complience) : 10
  • Java Build Path (JRE System Libraries) : 10

现在, import 语句抛出错误讯息:

The import javax.annotation.PostConstruct cannot be resolved

错误也会在 @PreDestroy 注释上发生

and this error also happen on @PreDestroy annotation too.

为什么会这样? Java 10会发生什么?如果我仍想将Java Compiler和JRE系统库版本保留到Java 10,如何解决这个问题?

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?

谢谢。

推荐答案

您可以尝试向pom.xml添加注释依赖项,以便它们可用于Spring:

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>

这篇关于导入javax.annotation。*无法在Eclipse的Java 10编译器中解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆