4 Replies Latest reply on Dec 21, 2016 4:13 PM by Thomas Meyer

    Problems with Classloader / Classpath during deploying a WAR

    Vagharshak Baghdasaryan Newbie

      Hello,

       

      maybe somebody can hlp in following issue.

       

      I am deploying a test archive via MavenImporter in following way:

       

      {code}
      public static WebArchive createServiceDeployment() {

       

      WebArchive serviceArchive = ShrinkWrap.create(MavenImporter.class)
      .configureFromFile(new File("C:/Users/vbaghdas/.m2/settings.xml"))
      .loadPomFromFile("../dsuite-parent-demo-service/dsuite-parent-demo-service-impl/pom.xml")
      .importBuildOutput()
      .as(WebArchive.class);
      System.out.println(serviceArchive.toString(true));
      return serviceArchive;
      }
      {code}

       

      During deploying folowing Exception happens:

       

      Caused by: java.lang.ClassCastException: org.springframework.context.annotation.ScopedProxyMode cannot be cast to org.springframework.context.annotation.ScopedProxyMode

        at org.springframework.context.annotation.AnnotationScopeMetadataResolver.resolveScopeMetadata(AnnotationScopeMetadataResolver.java:86) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:250) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:144) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:275) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:237) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:204) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:173) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

        at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

        at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:150) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

        at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:130) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

        at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:86) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]

        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) ~[tomcat-embed-core-8.5.4.jar:8.5.4]

        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) ~[tomcat-embed-core-8.5.4.jar:8.5.4]

        ... 10 more

       

      I checked my classpath - I have only 1 version of problematic spring-context jar, but it appears twice within classpath, as, by the way, each of other jars added to the classpath. Could that be the problem?

       

      Thank You and regards,

      Vagharshak Baghdasaryan

        • 1. Re: Problems with Classloader / Classpath during deploying a WAR
          Vagharshak Baghdasaryan Newbie

          Sorry, I checked my classpath - I I have only 1 version of problematic spring-context jar, and I have it indeed only once in the classpath - so I uderstand the problem even fewer now ...

          • 2. Re: Problems with Classloader / Classpath during deploying a WAR
            Vagharshak Baghdasaryan Newbie

            Ok, actually I found the way to exclude doubled "boarding" of spring libs ny adding following snippet into arquillian. xml:

             

            {code}

            <extension qualifier="spring-deployer">

                    <property name="auto-package">false</property>

            </extension>

            {code}

             

            But now I'am struggling with the next problem:

             

            Caused by: java.lang.NoSuchMethodException: de.bonprix.configuration.IntegrationDemoAuthenticationConfiguration$$EnhancerBySpringCGLIB$$9006ca5.CGLIB$SET_THREAD_CALLBACKS([Lorg.springframework.cglib.proxy.Callback;)

              at java.lang.Class.getDeclaredMethod(Class.java:2130) ~[?:1.8.0_66]

              at org.springframework.cglib.proxy.Enhancer.getCallbacksSetter(Enhancer.java:809) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.proxy.Enhancer.access$000(Enhancer.java:63) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.proxy.Enhancer$EnhancerFactoryData.<init>(Enhancer.java:414) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.proxy.Enhancer.wrapCachedClass(Enhancer.java:709) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:94) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_66]

              at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:480) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:337) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:135) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:107) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:406) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:263) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:130) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

              at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

              at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

              at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

              at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:150) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

              at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:130) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

              at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:86) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]

              at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]

              at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) ~[tomcat-embed-core-8.5.4.jar:8.5.4]

              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) ~[tomcat-embed-core-8.5.4.jar:8.5.4]

              ... 10 more

             

            IntegrationDemoAuthenticationConfiguration is a spring configuration class file with defined beans within it. My test class bind it by doing

            @SpringAnnotationConfiguration(classes = { IntegrationDemoAuthenticationConfiguration.class, ...})

            • 3. Re: Problems with Classloader / Classpath during deploying a WAR
              Vagharshak Baghdasaryan Newbie

              I found the reason for the problem.

               

              The Java Spring configuration classes, which are added to the test class via @SpringAnnotationConfiguration, should be also added to the test archive via addClasses()

              • 4. Re: Problems with Classloader / Classpath during deploying a WAR
                Thomas Meyer Newbie

                Hi,

                 

                today i did stumble upon a similar problem. i have a web app that includes the jersey jax-rs library. When run under the junior arquillian runner there seems to be a conflict of the jersey classes existing in the war file, i.e. Tomcat web app class loader and in the maven/plexus class world class loader. Trying to us the jax-rs client in the arquillian test @runasclient and in the web app itself crashes the we app. I wonder how to solve this problem.

                 

                the arquillian at runner should probably different classloaders for the tomcat embedded container and the execution of the client side tests.

                 

                maybe there is a way to exclude the maven dependencies from the resulting war file or from the junior classpath. I tried to use the maven fail safe plugin option excludesystem classloaders but without a good result. I'll investigate this problem deeper tomorrow.

                 

                just my 2 cents