【问题标题】:How to publish CXF webservice on Jetty server under Spring?Spring下如何在Jetty服务器上发布CXF webservice?
【发布时间】:2012-05-08 10:16:48
【问题描述】:

我目前正在开发一个独立的 spring 应用程序(不在容器中)。此应用程序需要提供 Servlet 和 WebService。所以我选择了apache cxf和jetty。

我设法让它工作,但我有两个独立的 Jetty 实例正在运行,一个用于 servlet,另一个用于 cxf。所以我的问题是,我如何指定 CXF 使用哪个 Jetty Server 实例?

以下是我的配置摘录。

http 服务器设置

<bean id="http-server" class="org.eclipse.jetty.server.Server"
    init-method="start" destroy-method="stop">

    <property name="connectors">
        <list>
            <bean class="org.eclipse.jetty.server.nio.SelectChannelConnector">
                <property name="port" value="8080" />
            </bean>
        </list>
    </property>
    <property name="handler">
        <bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerList">
            <property name="handlers">
                <list>
                    <ref bean="ServletContainer" />
                    <bean class="org.eclipse.jetty.server.handler.DefaultHandler" />
                </list>
            </property>
        </bean>
    </property>
</bean>

以上方法适用于 servlet...

CXF 设置

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<jaxws:endpoint id="WebService" implementor="com.MyWebServiceImp"
    address="/ws">
    <jaxws:features>
        <bean class="org.apache.cxf.feature.LoggingFeature" />
    </jaxws:features>
    <jaxws:properties>
        <entry key="faultStackTraceEnabled" value="false" />
        <entry key="exceptionMessageCauseEnabled" value="false" />
        <entry key="schema-validation-enabled" value="true" />
    </jaxws:properties>
</jaxws:endpoint>

通过上述配置,系统启动,但网络服务没有“发布”到码头服务器,日志中没有任何“异常”。

我几乎尝试了所有我能在 Google 上找到或找到的东西。任何信息或建议都将不胜感激,因为我过去几天一直在这方面。

谢谢

【问题讨论】:

    标签: java spring jetty jax-ws cxf


    【解决方案1】:

    这是一个有点不同的答案,你会像现在一样通过 spring 创建你的应用程序,但是使用 maven 你会发布你的应用程序,同时在这里构建它是如何,你的 pom.xml 插件配置:

    <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>7.0.2.v20100331</version>
        <configuration>
            <webAppConfig>
                <contextPath>/yourapplication</contextPath>
                <descriptor>
                    ${basedir}/src/main/webapp/WEB-INF/jetty/jetty-web.xml
                </descriptor>
            </webAppConfig>
            <scanIntervalSeconds>5</scanIntervalSeconds>
            <stopPort>9966</stopPort>
            <stopKey>foo</stopKey>
            <connectors>
                <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                    <port>9080</port>
                    <maxIdleTime>60000</maxIdleTime>
                </connector>
            </connectors>
        </configuration>
        <executions>
            <execution>
                <id>start-jetty</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <daemon>true</daemon>
                </configuration>
            </execution>
            <execution>
                <id>stop-jetty</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>stop</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    您的 web xml 是上面 pom 中指定的 jetty-web.xml。因此,将您的 cxf Web 服务发布到码头服务器会很容易。假设一切设置正确,只需 mvn clean install 会将您的服务发布到码头。

    【讨论】:

    • 我想我明白你在说什么。但是我没有 Web.xml,我不想使用 maven 来启动它。
    • @Paul 抱歉只是替代答案,如果您还没有的话,可以看看这个apache-wicket.1842946.n4.nabble.com/… ..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多