SpringMVC整合cxf webservice出现提示No service was found解决办法
2018-04-09 18:08
573 查看
一、项目环境
SpringMVC框架 版本:4.3.1
CXF 版本:3.1.6
二、问题现象
配置好相关配置文件,验证webService是否发布成功,访问: http://localhost:8080/CXF_Spring/webservice/HelloWorld?wsdl 页面提示:
No service was found
后台提示:
WARNING: Can't find the the request for http://localhost:8080/CXF_Spring/webservice/HelloWorld's Observer
三、问题分析
出现上述提示则意味着CXF的核心控制器没起作用,CXF的核心控制器要依赖Spring的ContextLoaderListner,而SpringMVC用的是DiapacherServlet的配置方式。问题搞清楚了,那么解决方案就很明显了。
四、解决方案(其实也是整合SpringMvc和cxf的完整教程)
拆分配置文件,spring-servlet.xml(DiapacherServlet配置方式)中配置Controller组件,root-context.xml(ContextLoaderListner配置方式)中配置普通bean和CXF。
详细配置如下(只展示与解决这个问题有关的配置):
web.xml
spring-servlet.xml(DiapacherServlet配置方式)
该配置文件没有与CXF有关的配置,略过
root-context.xml(ContextLoaderListner配置方式)
在该配置文件<beans>中首先要额外加上这些链接:xmlns:jaxws="http://cxf.apache.org/jaxws" 和
xsi:schemaLocation=" http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
pom.xml
HelloWorld.java
HelloWorldImpl.java
上述配置完成后,访问 http://localhost:8080/CXF_Spring/webservice/HelloWorld?wsdl即可看到发布的webservice的xml了。
访问http://localhost:8080/CXF_Spring/webservice/可查看发布的接口列表。
SpringMVC框架 版本:4.3.1
CXF 版本:3.1.6
二、问题现象
配置好相关配置文件,验证webService是否发布成功,访问: http://localhost:8080/CXF_Spring/webservice/HelloWorld?wsdl 页面提示:
No service was found
后台提示:
WARNING: Can't find the the request for http://localhost:8080/CXF_Spring/webservice/HelloWorld's Observer
三、问题分析
WARNING: Can't find the the request for http://localhost:8080/CXF_Spring/webservice/HelloWorld's Observer
出现上述提示则意味着CXF的核心控制器没起作用,CXF的核心控制器要依赖Spring的ContextLoaderListner,而SpringMVC用的是DiapacherServlet的配置方式。问题搞清楚了,那么解决方案就很明显了。
四、解决方案(其实也是整合SpringMvc和cxf的完整教程)
拆分配置文件,spring-servlet.xml(DiapacherServlet配置方式)中配置Controller组件,root-context.xml(ContextLoaderListner配置方式)中配置普通bean和CXF。
详细配置如下(只展示与解决这个问题有关的配置):
web.xml
<listener> <description>Define spring4.x listener.</description> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <description>Define applicationContext.xml location.</description> <param-name>contextConfigLocation</param-name> <param-value> classpath:root-context.xml </param-value> </context-param> <servlet> <description>SpringMVC dispatcher servlet.</description> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <description>Define springMVC configuration location.</description> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/webservice/*</url-pattern> </servlet-mapping>
spring-servlet.xml(DiapacherServlet配置方式)
该配置文件没有与CXF有关的配置,略过
root-context.xml(ContextLoaderListner配置方式)
在该配置文件<beans>中首先要额外加上这些链接:xmlns:jaxws="http://cxf.apache.org/jaxws" 和
xsi:schemaLocation=" http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
<!-- 引cxf的一些核心配置 --> <import resource="classpath:META-INF/cxf/cxf.xml" /> <!-- cxf 3.1.6版本不存在如下两个xml,可能在较早版本中会存在且需要需要 <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> --> <bean id="hello" class="com.dx.webservice.HelloWorldImpl" /> <jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" />
pom.xml
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.0-alpha4</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>3.1.6</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>3.1.6</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-jetty</artifactId> <version>3.1.6</version> </dependency>
HelloWorld.java
import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; @WebService //@WebService(targetNamespace="tallent") //如果不写targetNamespace的值时,默认是包反转,比如服务器项目中包是com.gstd.hw,那么默认值为hw.gstd.com,如果在另外 //的项目客户端中调用,则创建接口类HelloWorld时,类名可以不一样,但是targetNamespace必须一样。不然调用不成功!最好自己定义一个名称 @SOAPBinding(style = Style.RPC) public interface HelloWorld { String sayHi(String text); }
HelloWorldImpl.java
import javax.jws.WebParam; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; @WebService(endpointInterface = "com.dx.webservice.HelloWorld")////这里指定服务的接口类的路径,也可以不写 @SOAPBinding(style = Style.RPC) public class HelloWorldImpl implements HelloWorld{ @Override public String sayHi(@WebParam(name = "text")String text) { System.out.println("sayHi called"); return "Hello " + text; } }
上述配置完成后,访问 http://localhost:8080/CXF_Spring/webservice/HelloWorld?wsdl即可看到发布的webservice的xml了。
访问http://localhost:8080/CXF_Spring/webservice/可查看发布的接口列表。
相关文章推荐
- webservice 出现No service was found
- cxf调用WebService时出现No operation was found with the name {http://impl.server.test.com/}helloWorld
- SpringMVC出现no mapping found for http request的解决办法
- VMware下Linux安装VMWare Tools 后无法启动图形界面,出现"no screens found" 的解决办法
- the service mysql56 was not found in the Windows services的解决办法
- linux下安装mysql源码包出现configure: error: No curses/termcap library found的解决办法
- spark 程序在提交到集群上,出现ClassNoFound的错误,解决办法
- Tortoise-SVN 出现“unable to connect to a repository at url no element found”解决办法
- 安装mysql,在./configure时出现错误:error: No curses/termcap library found的解决办法
- 安装mysql,在./configure时出现错误:error: No curses/termcap library found的解决办法(1)
- 安装mysql,在./configure时出现错误:error: No curses/termcap library found的解决办法
- 调试出现"no matching symbolic information found"原因以及解决办法
- 源码编译出现的问题cmake 提示C compiler was not found和Cxx complier was not found解决办法
- SpringMVC 出现"The request sent by the client was syntactically incorrect ()"解决办法
- 安装mysql,在./configure时出现错误:error: No curses/termcap library found的解决办法
- 关于android开发中编译时出现“No Launcher activity found!”的解决办法
- IAR出现Copy protection check, No valid license found for this product的解决办法
- java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testDemo]出现原因及解决办法
- Android Studio安装后提示No JVM installation found解决办法
- 首次安装Qt后,创建项目时出现“No valid kits found” 的解决办法