我目前正在开发一个独立的 Spring 应用程序(不在容器中)。该应用程序需要为 Servlet 和 WebService 提供服务。所以我选择了apache cxf和jetty。
我设法让它工作,但我有两个单独的 Jetty 实例在运行,一个用于 servlet,另一个用于 cxf。所以我的问题是,如何指定 CXF 使用哪个 Jetty 服务器实例?
以下是我的配置的摘录。
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>
通过上述配置,系统启动,但 Web 服务未“发布”到 jetty 服务器,日志中也没有任何“异常”。
我几乎已经尝试了所有我能想到的或在 Google 上找到的东西。任何信息或建议将不胜感激,因为我过去几天一直在这方面。
谢谢
最佳答案
这里有一个有点不同的答案,您可以像现在一样通过 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 服务发布到 jetty 服务器会很容易。假设一切都设置正确,只需 mvn clean install
即可将您的服务发布到 jetty。
关于java - Spring下如何在Jetty服务器上发布CXF webservice?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10496697/