如何在JAX-RS Apache CXF,Apache Camel,Spring应用程序中删除嵌入式jetty并在独立的Tomcat上部署

时间:2013-09-03 09:37:58

标签: cxf jax-rs embedded-jetty

我正在使用Apache CXF,Apache Camel和Spring with 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运行时:使用intellij idea中的端口8081运行,我的appplication正在端口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。

2 个答案:

答案 0 :(得分:0)

请提供有关您使用的mvn命令和POM文件的更多信息。

根据提供的信息,我假设您使用的是“mvn * install”。使用“mvn clean compile package”。使用它,它只会创建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捆绑包中。结帐maven排除了解更多详情

答案 1 :(得分:0)

最后,当我从jaxrs-server地址配置中删除绝对位置并保留相对上下文路径时,它工作正常。