bsc*_*ott 3 jersey maven-3 maven jersey-2.0 spring-boot
更新:所以我只想指出,在提交这个问题之前,我尝试了在类似的 stackoverflow 问题(例如this )上看到的解决方案。它仍然给我运行时错误,所以我决定写这个问题。mvn dependency:tree就是我一直在寻找的东西,所以谢谢@dunni。通过mvn dependency:tree,我能够找到破坏我的应用程序的球衣依赖项的实际名称,并通过将其更改为以下内容来更新排除:
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
Run Code Online (Sandbox Code Playgroud)
到:
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</exclusion>
</exclusions>
Run Code Online (Sandbox Code Playgroud)
现在可以了。
很长一段时间以来,我一直在使用 1 个内部公司存储库开发这个 Spring Jersey REST 应用程序。现在,我发现我需要使用的库仅存在于第二个内部公司存储库中。我更新了 .m2 -> settings.xml 配置以添加对新存储库的引用,如下所示:
<settings>
<mirrors>
<mirror>
<id>internal-repository1</id>
<name>name</name>
<url>http://repo1.company.com/repositories/</url>
<mirrorOf>*, !repo2</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>profile</id>
<repositories>
<repository>
<id>repo1</id>
<name>repo1</name>
<url>http://repo1.company.com/repositories/</url>
</repository>
<repository>
<id>repo2</id>
<name>repo2</name>
<url>http://repo2.company.com/respositories/</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>profile</activeProfile>
</activeProfiles>
</settings>
Run Code Online (Sandbox Code Playgroud)
这有效。我可以在 System.out 中看到它尝试从 repo1.company.com/repositories/ 下载 repo2 独占依赖项。它失败,然后尝试从 repo2.company.com/repositories 下载它并且成功。构建继续进行,最终 tomcat 在 localhost:8080 上启动,一切正常。
问题是,每当我尝试访问我设置的任何 Jersey REST 端点时,我都会收到问题标题中提到的运行时错误:
ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[my.package.name]
- Allocate exception for servlet my.package.name.JerseyConfig
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
Run Code Online (Sandbox Code Playgroud)
我知道问题出在我尝试使用的这个新依赖项中的某个地方。当我注释掉 pom.xml 中的依赖项并重新运行应用程序时,一切正常。所有 REST 端点均正常运行。取消注释依赖项,重新运行应用程序,然后尝试访问我的 REST 端点,我收到上述错误。
我如何找出为什么这种依赖关系在运行时破坏了我的 Jersey 应用程序?
通过查看错误,我可以猜测 jar 文件中存在一些冲突。请检查类路径上是否同时存在 JAX-RS 1 和 JAX-RS 2 jar。Jersey 2 使用 JAX-RS 2 (javax.ws.rs-api-2.0.1.jar),但如果您还有 jsr311-api.jar,即 JAX-RS 1,则有一个 javax.ws.rs每个 jar 中的 .core.Application 。但是 jsr311-api 应用程序没有 getProperties() 方法。
| 归档时间: |
|
| 查看次数: |
8061 次 |
| 最近记录: |