【发布时间】:2019-03-07 13:10:59
【问题描述】:
我正在将我们的项目从 java 8 迁移到 11。
作为第一步,我使用源和目标兼容性 1.8 对其进行编译,但尝试在 openjdk-11 上运行应用程序。
在开发过程中,我们使用 jetty:run 目标来启动应用服务器。此目标因此错误而失败:
Caused by: java.lang.NoSuchMethodError: javax.annotation.Resource.lookup()Ljava/lang/String;
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.<init>(CommonAnnotationBeanPostProcessor.java:621) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.lambda$buildResourceMetadata$0(CommonAnnotationBeanPostProcessor.java:383) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.util.ReflectionUtils.doWithLocalFields(ReflectionUtils.java:713) ~[spring-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.buildResourceMetadata(CommonAnnotationBeanPostProcessor.java:365) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.findResourceMetadata(CommonAnnotationBeanPostProcessor.java:350) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:298) ~[spring-context-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1043) ~[spring-beans-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:550) ~[spring-beans-5.1.0.RELEASE.jar:5.1.0.RELEASE]
... 63 more
我找到了错误版本的 @Resource 注释的来源:
URL [jar:file:[...]/.m2/repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar!/javax/annotation/Resource.class]
URL [jar:file:[...]/Applications/apache-maven-3.5.4/lib/jsr250-api-1.0.jar!/javax/annotation/Resource.class]
似乎 maven 正在将其 /lib/ 文件夹中的所有库放在插件类路径中
我猜当我在 jdk 1.8 上运行它时,jdk 中的 @Resource 注释具有优先权(因为我从未见过这个错误),但现在不再是这种情况了(因为不再包含此注释在 jdk11 中)。
我有什么办法摆脱这个老班?
(我可以从 maven 安装升级 lib,但我宁愿将其保留为最后的手段,这将要求从事该项目的每个人都调整其 maven 安装)。
编辑:jetty:run-forked 目标也可以正常工作,但有了这个目标,我无法保留插件的 <webApp> 配置部分。
这似乎真的是一个 Maven 类路径隔离问题。
【问题讨论】:
标签: java maven maven-jetty-plugin