2011-08-15 56 views
7

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

我有以下配置文件的简单Java的第一个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> 

的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> 

根据到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为“正在使用”,并使用嵌入的码头例如,如果它不是。 http://cxf.apache.org/docs/xfire-migration-guide.html#XFireMigrationGuide-HTTPandServletSetup。所以,由于某些原因,CXF正在使用嵌入式码头实例而不是我的servlet。但是,除了web.xml中的HelloWorldServlet之外,我不知道需要哪些进一步的配置,CXF文档对我没有帮助。

回答

12

答案当然很简单(就是简单的即兴演奏)。在我的cxf bean定义中,我没有导入如此处所示的“cxf-servlet.xml”文件http://cxf.apache.org/docs/servlet-transport.html。如果这个文件没有被导入,cxf会假定它应该使用嵌入式jetty实例,而不是我的CXF servlet。我的猜测是码头实例仅适用于指定绝对发布地址的端点。

+0

+1在你的桌子上敲打你的头 –

+1

感谢你发布解决方案,我有完全相同的问题,几乎把我的头撞在桌子上:-) – user1339772

0

它不应该是

address="/HelloWorldService" 

+0

感谢您指出。我没有尝试/ HelloWorldService,但它似乎仍然无法正常工作。 – Jpnh

+0

请在您的端点中添加serviceName =“service'sName”并尝试 – tamilnad

+0

谢谢。我没有提到我在Web服务实现上的JaxWS注释中配置了服务名称。 – Jpnh