由于StackOverflowError,无法完成对Web应用程序[/ app]的注释的扫描

Mat*_*ias 42 java eclipse spring spring-mvc maven

我正在使用STS(eclipse插件)和maven开发Spring MVC应用程序.

为了创建项目,我按照STS向导进行了一个新的"Spring MVC项目".之后,我向其他项目和库添加了一些依赖项.

但是,当我现在尝试将项目部署到STS的集成vFabric服务器时,我有时会遇到异常:

SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/wsa]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    ...
Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/app] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.bouncycastle.asn1.ASN1EncodableVector->org.bouncycastle.asn1.DEREncodableVector->org.bouncycastle.asn1.ASN1EncodableVector]
    at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2179)
    ...
Run Code Online (Sandbox Code Playgroud)

当发出"maven clean",然后是"maven install"并重新启动服务器时,异常有时不会被抛出并且应用程序正常工作.然而,大多数时候,它不起作用.

我想没有必要扫描bouncycastle依赖项的注释.
我可以以某种方式禁用某些罐子的扫描吗?

我已经尝试添加metadata-complete="true"到我的web.xml并增加堆栈大小而没有结果.

我该怎么做才能解决这个问题?

ami*_*dri 59

在我的例子中org.bouncycastle.asn1.DEREncodableVector,导致循环依赖的类由类路径中的两个jar提供.

bcprov-jdk15on-1.47.jar 和 bcprov-jdk16-1.45.jar

排除了不需要的jar(bcprov-jdk16-1.45.jar)并且效果很好


g00*_*00b 19

你有一个循环依赖.org.bouncycastle.asn1.ASN1EncodableVector取决于org.bouncycastle.asn1.DEREncodableVector哪个取决于org.bouncycastle.asn1.ASN1EncodableVector... 这是一个无限循环,所以你得到了一个StackOverflowException.

如果您在Eclipse中安装了Maven插件,请查看依赖关系层次结构并查找这些类.我在这里找到了一个有类似问题的人,他通过查看依赖树然后添加排除来解决循环依赖性来解决它.


小智 8

我刚遇到这个问题。其他人已经给出了这个问题的答案。我想说点别的。

我猜您正在使用maven-shade-plugin或类似的东西将所有依赖项打包到 Uber jar 中,对吗?

你可以看到grepcode那个bcprov-jdk15on:1.52定义DEREncodableVector为

public class DEREncodableVector extends ASN1EncodableVector
Run Code Online (Sandbox Code Playgroud)

虽然bcprov-jdk14:1.38定义ASN1EncodableVector为

public class ASN1EncodableVector extends DEREncodableVector
Run Code Online (Sandbox Code Playgroud)

和maven-shade-plugin,当存在两个或更多相同的类时,它会随机选择一个类。当它选择这种组合时,就会发生循环依赖。如果它选择其他组合,您的应用程序可能会正常工作。与你描述的相符

然而,大多数时候,它不起作用。

这是一个概率事件。


小智 7

我的 spring boot 项目也遇到了同样的问题。为了找出冲突的依赖项,我从项目目录发出以下命令:

mvn dependency:tree -Dverbose -Dincludes=org.bouncycastle

从输出中发现以下信息:

[INFO] +- org.springframework.cloud:spring-cloud-starter-openfeign:jar:2.1.0.RC3:compile
[INFO] |  \- org.springframework.cloud:spring-cloud-starter:jar:2.1.0.RC2:compile
[INFO] |     \- org.springframework.security:spring-security-rsa:jar:1.0.7.RELEASE:compile
[INFO] |        \- org.bouncycastle:bcpkix-jdk15on:jar:1.60:compile
[INFO] |           \- org.bouncycastle:bcprov-jdk15on:jar:1.60:compile
[INFO] \- com.cybersource:cybersource-rest-client-java:jar:0.0.16:compile
[INFO]    \- com.cybersource:AuthenticationSdk:jar:0.0.8:compile
[INFO]       \- org.bouncycastle:bcprov-jdk16:jar:1.45:compile

Run Code Online (Sandbox Code Playgroud)

在这里我们可以看到 openfeign 和 cybersource-rest-client 使用不同版本的 bcprov-jdk 包。由于 cybersource-rest-client 具有此包的更新版本,因此我从 pom.xml 中的 openfeign 中排除了此依赖项,如下所示:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Run Code Online (Sandbox Code Playgroud)

这帮助我解决了这个问题。


Vic*_*azi 5

这发生在我身上使用

        <groupId>org.bouncycastle</groupId>
        <artifactId>bcpkix-jdk15on</artifactId>
        <version>1.54</version>
Run Code Online (Sandbox Code Playgroud)

我将其升级为

        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk16</artifactId>
        <version>1.46</version>
Run Code Online (Sandbox Code Playgroud)

这似乎已经解决了它