无法使用我的Spring框架运行Arquillian

时间:2015-07-27 07:20:08

标签: spring maven jpa cdi jboss-arquillian

我试图使用spring + JPA + JSF + Primefaces项目运行我的基本测试用例时遇到以下错误

你能帮忙吗?

16:52:51,394 INFO  [org.springframework.data.jpa.repository.cdi.JpaRepositoryExtension] (MSC service thread 1-11) Activating CDI extension for Spring Data JPA repositories.
    ERROR [org.jboss.msc.service.fail] MSC000001: Failed to start service jboss.deployment.unit."787b2f47-cedc-492a-bb96-e58a02b72772.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."787b2f47-cedc-492a-bb96-e58a02b72772.war".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "787b2f47-cedc-492a-bb96-e58a02b72772.war"
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_45]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_45]
        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_45]
    Caused by: java.util.ServiceConfigurationError: javax.servlet.ServletContainerInitializer: Provider org.springframework.web.SpringServletContainerInitializer not found
        at java.util.ServiceLoader.fail(ServiceLoader.java:239) [rt.jar:1.8.0_45]
        at java.util.ServiceLoader.access$300(ServiceLoader.java:185) [rt.jar:1.8.0_45]
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372) [rt.jar:1.8.0_45]
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) [rt.jar:1.8.0_45]
        at java.util.ServiceLoader$1.next(ServiceLoader.java:480) [rt.jar:1.8.0_45]
        at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.deploy(ServletContainerInitializerDeploymentProcessor.java:112)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
        ... 5 more

    ERROR [org.jboss.as.controller.management-operation] JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "787b2f47-cedc-492a-bb96-e58a02b72772.war")]) - failure description: {
        "JBAS014671: Failed services" => {"jboss.deployment.unit.\"787b2f47-cedc-492a-bb96-e58a02b72772.war\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"787b2f47-cedc-492a-bb96-e58a02b72772.war\".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment \"787b2f47-cedc-492a-bb96-e58a02b72772.war\"
        Caused by: java.util.ServiceConfigurationError: javax.servlet.ServletContainerInitializer: Provider org.springframework.web.SpringServletContainerInitializer not found"},
        "JBAS014771: Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"787b2f47-cedc-492a-bb96-e58a02b72772.war\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"787b2f47-cedc-492a-bb96-e58a02b72772.war\".beanmanager]"]
    }
    ERROR [org.jboss.as.server] JBAS015870: Deploy of deployment "787b2f47-cedc-492a-bb96-e58a02b72772.war" was rolled back with the following failure message: 
    {
        "JBAS014671: Failed services" => {"jboss.deployment.unit.\"787b2f47-cedc-492a-bb96-e58a02b72772.war\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"787b2f47-cedc-492a-bb96-e58a02b72772.war\".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment \"787b2f47-cedc-492a-bb96-e58a02b72772.war\"
        Caused by: java.util.ServiceConfigurationError: javax.servlet.ServletContainerInitializer: Provider org.springframework.web.SpringServletContainerInitializer not found"},
        "JBAS014771: Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"787b2f47-cedc-492a-bb96-e58a02b72772.war\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"787b2f47-cedc-492a-bb96-e58a02b72772.war\".beanmanager]"]
    }
    INFO  [org.jboss.as.connector.subsystems.datasources] JBAS010409: Unbound data source [java:/jdbc/cdis-db]
    INFO  [org.jboss.as.server.deployment] JBAS015877: Stopped deployment 787b2f47-cedc-492a-bb96-e58a02b72772.war (runtime-name: 787b2f47-cedc-492a-bb96-e58a02b72772.war) in 370ms
    INFO  [org.jboss.as.controller] JBAS014774: Service status report
    JBAS014775:    New missing/unsatisfied dependencies:
          service jboss.deployment.unit."787b2f47-cedc-492a-bb96-e58a02b72772.war".beanmanager (missing) dependents: [service jboss.deployment.unit."787b2f47-cedc-492a-bb96-e58a02b72772.war".weld.weldClassIntrospector] 
    JBAS014777:   Services which failed to start:      service jboss.deployment.unit."787b2f47-cedc-492a-bb96-e58a02b72772.war".INSTALL

我的部署如下,数据源定义良好。 pom-test.xml包含我的项目所需的依赖项,包括sprint-test,spring-core和sprint-data-jpa等。

@Deployment
public static Archive<?> createTestArchive() {
    Archive jar = ShrinkWrap.create(WebArchive.class)
            .addClasses(Greeter.class, PhraseBuilder.class)
            .addAsLibraries(
                    Maven.resolver().loadPomFromClassLoaderResource("META-INF/pom-test.xml")
                            .importRuntimeDependencies().resolve().withTransitivity().asFile())
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsWebInfResource("META-INF/jboss-ds.xml")
            // Deploy our test datasource
            ;
    System.out.println(jar.toString(true));
    return jar;

}

1 个答案:

答案 0 :(得分:0)

我在同事的帮助下完成了这项工作。 我必须改变一些事情

  1. 我不得不使用wildfly-arquillian-container-managed而不是embedded
  2. 依赖性 的groupId:org.wildfly
    的artifactId:wildfly-的Arquillian容器管理
    版本:8.2.1.Final

    1. 我没有用正确的WEB-INF配置文件创建war文件

      File[] files = Maven.resolver().loadPomFromFile("pom.xml")
              .importRuntimeDependencies().resolve().withTransitivity().asFile();
      
      WebArchive war = ShrinkWrap.create(WebArchive.class, "test-cdisonline.war")
              .addAsLibraries(files)
      
              // need to filter out non container tests
              .addPackages(true, Filters.include(".*ContainerTest.*"), "au.com.xxx.xxx")
              .addPackages(true, Filters.exclude(".*Test.*|.*ModelJPAConfig.*|.*ApplicationConfig.*"), "au.com.ibm.cdis")
      
              // need to added arquillian test to war
              .addPackages(true, "au.com.xxx.arquillian")
      
              // add as a resource forces persistence.xml into the WEB-INF/classess folder which is visible to classloader when
              // searching
              .addAsResource(new File(META_INF,"persistence.xml"),"META-INF/persistence.xml")
      
      
              .addAsResource(new File("src/test/resources/" + CDIS_ROOT, "pipeline-small.xlsx"), CDIS_ROOT + "/pipeline-small.xlsx")
              //WEB-INF
              // datasource definitions
              .addAsWebInfResource("wildfly-ds.xml")
              .addAsWebInfResource(new File(WEB_INF,"beans.xml"), "beans.xml")
      
              // this version of the web.xml remove resource refs as I haven't worked out how to define them dynamically during tests
              .addAsWebInfResource("test-web.xml", "web.xml")
      
               .addAsLibraries(new File(WEBAPP_LIB, "rio-theme-1.1.jar"))
      
              .addAsWebInfResource(new File(WEB_INF,"faces-config.xml"), "faces-config.xml")
              ;                                                         
      
      for (File f : new File(WEBAPP_SRC).listFiles(new FilenameFilter() {
          @Override
          public boolean accept(File dir, String name) {
              return name.toLowerCase().endsWith(".xhtml");
          }
      })) {
          war.addAsWebResource(f);
      }
      
      logger.info(war.toString(true));
      
      return war;