我正在使用Apache CXF,Apache Camel和Spring与Maven创建JAX-RS应用程序。当我运行应用程序时,它正在创建一个嵌入式码头并为请求提供服务。
我想删除嵌入式jetty,并使用war文件在独立的Tomcat上运行它。我尝试了许多可行的建议,但对我的情况不起作用。请给我一些建议。
我的POM包含
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>8.1.3.v20120416</version>
</dependency>
<build>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.12.v20130726</version>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<webApp>
<contextPath>myfashions</contextPath>
<defaultsDescriptor>
${basedir}/src/main/resources/webdefault.xml
</defaultsDescriptor>
</webApp>
</configuration>
</plugin>
</build>
当我使用jetty:run和intellij idea的8081端口运行时,我的应用程序正在8080端口上启动另一个嵌入式jetty服务器并提供请求。
当我删除所有的jetty依赖项和插件,并在tomcat中部署生成的WAR时,我得到的错误是
013-09-06_01:21:21 ERROR o.a.c.t.http.HTTPTransportFactory - Cannot find any registered HttpDestinationFactory from the Bus.
Sep 06, 2013 1:21:21 AM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'baseApi': Invocation of init method failed; nested exception is org.apache.cxf.service.factory.ServiceConstructionException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
请建议一种方法,这样我就可以在tomcat内部运行WAR,而无需启动嵌入式码头。
请提供有关您使用的 mvn 命令和 POM 文件的更多信息。
根据提供的信息,我假设您使用的是“mvn*install”。使用“mvn干净编译包”。使用它,它只会创建WAR文件,然后您可以将其复制到tomcat服务器中。
此外,如果您不打算使用 JETTY 进行部署,则必须将它们排除在 POM 中,否则它们将始终存在于您的类路径中。排除样本 -
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-continuation</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
</exclusion>
</exclusions>
这些JAR包含在CXF捆绑包中。Checkout maven排除以获取更多详细信息
最后,当我从jaxrs-server地址配置中删除绝对位置并保留相对上下文路径时,它工作了。