0 Replies Latest reply on Jul 26, 2016 10:26 AM by mirko ferioli

    Problem with @SpringWebConfiguration : java.lang.RuntimeException: Could not find the application context for servlet: CXFServlet

    mirko ferioli Newbie

      Hi, I've a problem with arquillian and sping extension.

      I need to test a jaxrs service implement with CXF and spring on jboss EAP 6.4.1

      In particular i've to test jpa part.

      it's the first time the use arquilian and perheps something wrong.

      I put everything under \src\test\resources

      in particular web.xml, arquilian.xml, applicationContext.xml and META-INF\persistence.xml

       

      this how i've created webarchive

       

      return ShrinkWrap.create(WebArchive.class, "spring-test.war")

        .addClasses(BenchmarksDAO.class,BenchmarksDAOImpl.class,BenchmarksHistory.class,BaseDAO.class,BaseDAOImpl.class,BenchmarksStaging.class,DataNav.class,BenchmarksServiceImpl.class, BenchmarksService.class)

                      .addAsWebInfResource("web.xml")

        .addAsWebInfResource("applicationContext.xml")

        .addAsResource("META-INF/persistence.xml")

        .addAsLibraries(springDependencies());

       

        }

       

        public static File[] springDependencies() {

       

        return Maven.resolver()

        .loadPomFromFile("pom.xml", "arquillian-jbossas-managed-7")

        .importRuntimeAndTestDependencies()

        .resolve()

        .withTransitivity()

        .asFile();

       

       

      and this is my web.xml

       

      <web-app xmlns="http://java.sun.com/xml/ns/javaee"

               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

               version="3.0">

        <display-name>StatPro_CXF</display-name>

        <description>StatPro_CXF Service</description>

        <context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>/WEB-INF/applicationContext.xml</param-value>

        </context-param>

        <listener>

        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

        </listener>

        <servlet>

        <servlet-name>CXFServlet</servlet-name>

        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>

        <load-on-startup>1</load-on-startup>

        </servlet>

        <servlet-mapping>

        <servlet-name>CXFServlet</servlet-name>

        <url-pattern>/*</url-pattern>

        </servlet-mapping>

      </web-app>

       

      this is my test

       

      @RunWith(Arquillian.class)

      @SpringWebConfiguration(servletName = "CXFServlet")

      public class BenckmarksServiceTest {

       

        @Deployment

          public static WebArchive create() {

        WebArchive war = Deployments.createDeployment();

        System.out.println(war.toString(true));

        return war;

         }

        @Autowired

        private BenchmarksDAO dao;

       

        @Test

        public void testGet() throws Exception {

        SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");

        Date datagiro = formatter.parse("21-07-2016");

        List<BenchmarksHistory> result = dao.getHistoryBenchmarks(datagiro);

        Assert.assertTrue(result.size() > 0);

       

        }

      }

       

      and this is the errror

       

       

      java.lang.RuntimeException: Could not find the application context for servlet: CXFServlet

        at org.jboss.arquillian.spring.integration.inject.container.WebApplicationContextProducer.getWebApplicationContext(WebApplicationContextProducer.java:89)

        at org.jboss.arquillian.spring.integration.inject.container.WebApplicationContextProducer.createApplicationContext(WebApplicationContextProducer.java:57)

        at org.jboss.arquillian.spring.integration.inject.container.WebApplicationContextProducer.createApplicationContext(WebApplicationContextProducer.java:41)

        at org.jboss.arquillian.spring.integration.lifecycle.AbstractApplicationContextLifecycleHandler.createApplicationContext(AbstractApplicationContextLifecycleHandler.java:200)

        at org.jboss.arquillian.spring.integration.lifecycle.AbstractApplicationContextLifecycleHandler.createTestApplicationContext(AbstractApplicationContextLifecycleHandler.java:170)

        at org.jboss.arquillian.spring.integration.lifecycle.AbstractApplicationContextLifecycleHandler.beforeClass(AbstractApplicationContextLifecycleHandler.java:108)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:497)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

        at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:497)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:497)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)

        at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:87)

        at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:201)

        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:426)

        at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54)

        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:218)

        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:115)

        at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:66)

        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:170)

        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:135)

        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:98)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)

        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)

        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)

        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)

        at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)

        at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)

        at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)

        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150)

        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)

        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)

        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)

        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:854)

        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)

        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926)

        at java.lang.Thread.run(Thread.java:745)

       

       

      Somone can help me please?

      Thanks

      Mirko