Unable to complete the scan for annotations for we

2020-01-30 06:08发布

问题:

I am developing a Spring MVC application using STS (eclipse plugin) and maven.

For creating the project, I followed the STS wizard for a new "Spring MVC project". Afterwards, I added some dependencies to other projects and libraries.

However, when I am now trying to deploy the project to the integrated vFabric server of STS, I sometimes get an exception:

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)
    ...

When issuing a "maven clean", followed by a "maven install" and a restart of the server, the exception sometimes doesn't get thrown and the application works fine. Yet, most of the times, it doesn't work.

I guess there is no need to scan the bouncycastle dependencies for annotations.
Can I somehow disable this scanning for some jars?

I already tried adding metadata-complete="true" to my web.xml and increasing the stack size with no result.

What can I do to fix this?

回答1:

In my case the org.bouncycastle.asn1.DEREncodableVector class, which was causing the cyclic dependency, was served by two jars in the class path.

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

Excluded the unwanted jar(bcprov-jdk16-1.45.jar) and it worked well



回答2:

You have a cyclic dependency. org.bouncycastle.asn1.ASN1EncodableVector depends on org.bouncycastle.asn1.DEREncodableVector which depends back on org.bouncycastle.asn1.ASN1EncodableVector which ... . This is an infinite cycle and so you're getting a StackOverflowException.

If you have the Maven plugin installed in Eclipse, look at the Dependency Hierarchy and look for these classes. I found someone with a similar issue here, he solved it by looking at the dependency tree and then adding an exclusion to break the cyclic dependency.



回答3:

I just encountered this problem. Others already give the answer to this problem. I would say something else.

I guess that you are using maven-shade-plugin or something alike that packaging all dependencies into an Uber jar, right?

You can see from grepcode that bcprov-jdk15on:1.52 defines DEREncodableVector as

public class DEREncodableVector extends ASN1EncodableVector

While bcprov-jdk14:1.38 defines ASN1EncodableVector as

public class ASN1EncodableVector extends DEREncodableVector

And with maven-shade-plugin, it would randomly choose a class when two or more same classes exist. And when it chooses this combination, cyclic dependency happens. If it choose other combinations, your application may work fine. It matches what you described

Yet, most of the times, it doesn't work.

It's a probabilistic event.



回答4:

This was happening to me using

        <groupId>org.bouncycastle</groupId>
        <artifactId>bcpkix-jdk15on</artifactId>
        <version>1.54</version>

I upgraded that to

        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk16</artifactId>
        <version>1.46</version>

and that seems to have fixed it



回答5:

I had the same problem and fixed it finally . Go to your pom and search for bouncycastle You should see more than one exclude one of them and it should fix it



回答6:

I have this error in tomcat 8 and jdk 1.8

04-Apr-2018 16:35:06.358 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myapp]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1141)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/myapp] 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:2110)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2054)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:2000)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1970)
    at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1923)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1163)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:775)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5105)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more

04-Apr-2018 16:35:06.359 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Error deploying web application directory [/usr/apache-tomcat-8.5.24.Core/webapps/myapp]
 java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myapp]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:756)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1141)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

And I found two jar with name bcprov-jdk*.jar in my app lib. I removed all of those and use bcprov-jdk15on-1.52.jar. In this way, my problem was solved.



回答7:

I had the same issue I remove every trace of bouncycastle library in the buildConfig file. No trace in dependecy or excludes. Just add the plug in crypto.2.0 and everything works fine!



回答8:

Also double check your lib folder under Tomcat to make sure the duplicate dependency is not present there.



回答9:

If it is already excluded in the build config and error still exist, you can try to clean your project's working directory before building.

maven clean

-

grails clean


回答10:

I had the same problem but with a different solution. My conflict was with bcprov-jdk15on-1.55.jar and tika-app-1.7.jar. Apparently tika includes bouncy castle, and in this case the older version of bouncy castle that causes the conflict.



回答11:

Doing mvn clean in jenkins workspace folder (where my project runs) and doing a Jenkins build (that deletes the old war file) worked for me.