Java 11 升级缺少 javax.annotation.security

标签 java spring-boot tomcat gradle

有一个 spring boot 应用程序,我正在升级到 java 11。war 文件部署在最新的 tomcat 9 中,它是用 open-jdk-11 启动的。

代码仍然在 Java 8 中编译。首先让它在 Java 11 上运行,然后从模块 hazzle 开始......

所以我添加了 compile 'javax.annotation:javax.annotation-api:1.3.2' 作为依赖但从 tomcat 开始产生(启动可运行的 jar 给出相同的结果):

Caused by: java.lang.IllegalAccessError: class org.apache.catalina.startup.WebAnnotationSet (in unnamed module @0x51d8cbdd) cannot access class javax.annotation.security.DeclareRoles (in module java.annotation) because module java.annotation does not export javax.annotation.security to unnamed module @0x51d8cbdd
at org.apache.catalina.startup.WebAnnotationSet.loadClassAnnotation(WebAnnotationSet.java:258) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.startup.WebAnnotationSet.loadApplicationListenerAnnotations(WebAnnotationSet.java:88) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:67) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.startup.Tomcat$FixContextListener.lifecycleEvent(Tomcat.java:973) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1420) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1410) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
        at java.lang.Thread.run(Thread.java:834) ~[?:?]

最佳答案

您正在运行哪个版本的 Spring Boot? Java 11 支持从 2.1 开始 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.1-Release-Notes

Java 11 Support

Spring Boot 2.1 remains compatible with Java 8 but now also supports Java 11. We have continuous integration configured to build and test Spring Boot against the latest Java 11 release.

关于Java 11 升级缺少 javax.annotation.security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53046492/

相关文章:

java - Junit断言

spring-boot - 从 SpringBoot 2.6.6 升级到 2.6.7 更改了验证行为(javax.validation.ConstraintDeclarationException : HV000151 )

spring-boot - 如何仅在 localhost 的 spring security 中禁用 csrf?

performance - 从另一台 PC 访问 Tomcat Web 应用程序速度慢

java - 无法在我的 Servlet 程序中重定向到外部 URL(如 google.com)

java - 如何在java中比较两个 double 值与字符串类型的关系?

java - 在 Windows Azure 上创建 Java Restful Web 服务

javascript - 测试类无法读取consul配置

java - 在 VM 上部署更多 Tomcat 实例是否有意义?

java - 使用 Java 在 for 循环之外返回值时遇到问题