使用Arquillian测试Spring REST服务 - ClassNotFoundException JspServlet

时间:2018-02-17 15:54:17

标签: java spring jboss-arquillian

我正在尝试为使用Spring编写的REST服务设置一个简单的Arquillian测试。这是我的SpringBoot应用程序:

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

和控制器:

@RestController
public class TestController {
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public ResponseEntity test() {
        return ResponseEntity.status(HttpStatus.OK).body("Hello world");
    }
}

然后我想测试它运行Arquillian测试:

@RunWith(Arquillian.class)
public class TestControllerTest {
    @Deployment(testable = false)
    public static WebArchive createDeployment() {
        File[] files = Maven.resolver()
                .loadPomFromFile("pom.xml")
                .importRuntimeDependencies()
                .resolve().withTransitivity()
                .asFile();
        return ShrinkWrap.create(WebArchive.class)
                .addPackage(pl.fuv.Application.class.getPackage())
                .addPackage(TestController.class.getPackage())
                .addAsLibraries(files);
    }

    @Test
    @RunAsClient
    public void callRest(@ArquillianResteasyResource final WebTarget webTarget) {
        Response response = webTarget.path("/test").request().get();
        String result = response.readEntity(String.class);
        assertEquals("Hello world", result);
    }
}

在部署期间,我得到运行时异常:

  

SEVERE:Web应用程序中的Servlet [jsp]   [/ 0a1cee74-c798-46af-9402-474168676ae6]抛出load()异常   java.lang.ClassNotFoundException:org.apache.jasper.servlet.JspServlet     在   org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)     在   org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)     在   org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:544)     在   org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:525)     在   org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)     在   org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1050)     在   org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)     在   org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4931)     在   org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5241)     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在   org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)     在   org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)     在   org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)     在   org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:986)     在   org.apache.catalina.startup.HostConfig $ DeployWar.run(HostConfig.java:1857)     在   java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)     在java.util.concurrent.FutureTask.run(FutureTask.java:266)at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:624)     在java.lang.Thread.run(Thread.java:748)

和Arquillian获得404 HTTP响应,调用该服务:

  

org.junit.ComparisonFailure:预期:Hello world实际
  :HTTP状态404 - 不   找到(...)

我的猜测是我以错误的方式构建了部署工件,缺少某些东西,但我找不到任何可能出错的信息。

1 个答案:

答案 0 :(得分:0)

您需要添加对jasper的依赖项:

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>jasper</artifactId>
    <version>6.0.32</version>
</dependency>