从 Tomcat 上运行的 CXF Web 服务获取 WSDL

Mar*_*sen 1 tomcat web-services web.xml cxf

答:我知道就解决方案而言,这不是那种顺利的事情,但我摆弄了 web.xml 和 servlet.xml 文件,出于某种原因,它现在可以工作了,我可以获得服务列表和 wsdl 文件现在就好了。我将我的新文件与下面写的旧文件进行了比较,唯一的区别是 web.xml 的名称是 CXFServlet 而不是 LoginService,并且我现在已经为 cxfservlet.xml 端点提供了一个地址。

我有一个问题,我(最终)在 Tomcat 上部署了 CXF Web 服务。或者,更确切地说,它确实启动了,并且当我部署和重新部署时,它不会在 tomcat 日志中产生任何警告或异常。问题是我无法检索相关服务的 WSDL。我开始认为我不像我想象的那样理解 web.xml 和 cxf.xml 文件。

当我写http://localhost:8080/services/Login?wsdl 时,我希望 WSDL 弹出,但我得到的只是 404。我做错了什么?正如我所说,我没有得到任何例外,那么我的问题是什么?

编辑:由于一些有用的反馈(我记得标记为有用),我意识到我可能在 web.xml 中设置了错误的上下文路径。我通过 tomcat 中的管理器应用程序在名为 LoginService.war 的文件中部署该服务。这引出了一个问题:我什至可以这样做吗?tomcat 会知道在 LoginService 库中查找 CXFServlet 类,还是会在 ROOT 中查找?我是否需要重新配置服务器以允许我从http://localhost:8080/LoginService 运行

网页.xml

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>LoginService</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:metadata/Login/cxfservlet.xml</param-value>
</context-param>
<listener>
<listener-class>
  org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>LoginService</servlet-name>
<servlet-class>
    org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginService</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

cxfservlet.xml

 <beans xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org
 /jaxws http://cxf.apache.org/schemas/jaxws.xsd">
 <jaxws:endpoint id="LoginService"
 implementor="orgserver.services.Login" wsdlLocation="WEB-INF/LoginService.wsdl"
 address="/">
 </jaxws:endpoint>
 </beans>
Run Code Online (Sandbox Code Playgroud)

sou*_*ica 5

您不需要设置 wsdlLocation ,除非除了http://localhost:8080/services/之外还有其他方法可以访问您的服务。wsdlLocation 也是一个 URL。

我假设您已将应用程序部署到 Tomcat 中的 ROOT.war(根上下文),因为 /services 之前没有上下文路径。

浏览到http://localhost:8080/services(无尾随 /)时显示什么?它应该为您提供可用服务的列表,包括 WSDL 地址。如果您将鼠标悬停在 WSDL 地址上,它将显示实际的 URL。