Arquillian:部署WAR时Classloader / Classpath的问题

时间:2016-11-28 15:36:14

标签: java maven integration jboss-arquillian

我正在通过MavenImporter以下列方式部署测试档案:

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;  
}  

在部署以下期间发生异常:

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

我检查了我的类路径 - 我只有1个版本的有问题的spring-context jar,而且我确实只有一次在类路径中 - 所以我现在理解的问题更少了

1 个答案:

答案 0 :(得分:0)

尝试运行maven依赖:树来获取依赖于此项目的jar,以确保只有一个spring jar被加载而没有重复的传递依赖jar