如何解决 java 错误:包 javax.annotation 不可见,Java 版本 9

Rya*_* Cy 5 java gradle spring-session

使用 gradle 在 Spring 会话示例下构建时:https ://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot-findbyusername.html

我遇到了关于 java.annotation 模块的错误,有人知道如何解决吗?

/spring-session/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java:22: error: package javax.annotation is not visible
import javax.annotation.PostConstruct;
            ^
  (package javax.annotation is declared in module java.xml.ws.annotation, which is not in the module graph)
warning: unknown enum constant When.MAYBE
  reason: class file for javax.annotation.meta.When not found
1 error
1 warning

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':spring-session-core:compileJava'.
> Compilation failed; see the compiler error output for details.
Run Code Online (Sandbox Code Playgroud)

我尝试在 build.gradle 中添加以下配置,但问题仍然存在。

tasks.withType(AbstractCompile) {
  options.compilerArgs += ["--add-modules", "java.xml.bind"]
}

tasks.withType(Test) {
  jvmArgs += ["--add-modules", "java.xml.bind"]
}
Run Code Online (Sandbox Code Playgroud)

Ith*_*har 5

我遇到了同样的错误:

warning: unknown enum constant When.MAYBE
reason: class file for javax.annotation.meta.When not found
Run Code Online (Sandbox Code Playgroud)

对我来说,这是因为我进行了注释处理,但lombok项目依赖项并未拾取该注释处理。

最后我添加了annotationProcessor依赖项的一部分,如下所示:

dependencies {
  // ...
  compile('org.springframework.boot:spring-boot-starter-web')
  compileOnly('org.projectlombok:lombok')
  testCompile('org.springframework.boot:spring-boot-starter-test')
  // ...
  annotationProcessor('org.projectlombok:lombok')
}
Run Code Online (Sandbox Code Playgroud)


Rya*_* Cy -5

看起来示例还没有升级到支持java9,降级到java8它运行良好。