CXF jaxws端点相对发布地址

Jpn*_*pnh 8 spring web-services cxf jax-ws

在我的CXF Web服务端点配置中尝试使用相对发布地址时遇到了很多困难.

我有一个简单的Java-first JAX-WS项目,其中包含以下配置文件:

applicationContent-cxf.xml:

<beans xmlns=...>
    ...
    <jaxws:endpoint
        id="helloWorldService"
        implementorClass="org.helloworld.ws.HelloWorldServiceImpl"
        implementor="#helloWorldServiceImpl" <!-- spring managed -->
        endpointName="sayHello"
        address="HelloWorldService"/>
</beans>
Run Code Online (Sandbox Code Playgroud)

web.xml中:

<web-app>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            WEB-INF/applicationContext.xml
            WEB-INF/applicationContext-cxf.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>HelloWorldServlet</servlet-name>
        <display-name>Hello World Servlet</display-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>HelloWorldServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

根据http://cxf.apache.org/docs/servlet-transport.html,似乎我应该能够指定发布地址,HelloWorldService并且服务的URL将解析为(例如)http:// localhost: 8080/services/HelloWorldService.但是当我尝试访问http:// localhost:8080/services/HelloWorldService?wsdl时,我得到了404.如果我将jaxws端点中的发布地址更改为绝对URL,http://localhost:8080/services/HelloWorldService我可以访问wsdl.

我想尽可能指定一个相对端点地址.我是使用CXF(以及编写Web服务)的新手,所以非常感谢任何帮助!

更新1:

请注意,我正在将我的Web服务部署到Tomcat 7.我不知道是什么记录它,但是我的启动日志中的一行是状态Setting the server's publish address to be HelloWorldService.如果有人需要更多信息来帮助我,请告诉我.

更新2:

似乎CXF检测CXFServlet是否"正在使用",如果不是,则使用嵌入式jetty实例.http://cxf.apache.org/docs/xfire-migration-guide.html#XFireMigrationGuide-HTTPandServletSetup.因此,由于某种原因,CXF使用嵌入式jetty实例而不是我的servlet.但是,除了我的web.xml中的HelloWorldServlet之外,我不知道我需要什么进一步的配置,而且CXF文档对我没有帮助.

Jpn*_*pnh 15

当然,答案很简单(敲打头上的简单,就是这样).在我的cxf bean定义中,我没有导入"cxf-servlet.xml"文件,如http://cxf.apache.org/docs/servlet-transport.html所示.如果未导入此文件,则cxf假定它应使用嵌入式jetty实例而不是我的CXF servlet.我的猜测是jetty实例只适用于指定绝对发布地址的端点.