java - springmvc整合cxf发布webservice
1.jar包已上传百度云盘,在jar包目录下
2.web.xml配置
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/application/applicationContext-*.xml</param-value>
</context-param>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
2.WEB-INF新建springmvc-servlet.xml (由于web.xml没有配置该xml路径和地址,所以名字不能改,位置放到这里就行)
配置内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd ">
<!-- 启动注解驱动-->
<mvc:annotation-driven/>
<!-- 启动包扫描功能,你的代码-->
<context:component-scan base-package="com.cxf.*" />
</beans>
3.src目录,包名一定要com.cxf.*,因为springmvc-servlet.xml配置自动扫描的这个。
com.cxf.service.imp就是你要发布的webservice。
先说一下com.cxf.service实现类代码注意点:
上面注解不要漏就行了;
com.cxf.service.imp代码注意点:
第一个红线是接口路径。
第二个红线随便取名,但是不能不取名。发布后,在wsdl上会看看这个。
4.WEB-INF下新建目录和文件 application/applicationContext-cxf.xml,文件名和路径就是这个,不准改。因为web.xml这样配置的。哈哈哈。(其实applicationContext-cxf.xml的名字可以小改,自己理解吧)
内容:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- cxf3.0及以上版本不需要再手工引入
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> -->
<!-- webservice服务l,implementor对应的是实现类,address,是访问的名字-->
<jaxws:endpoint id="HelloWorld" implementor="com.cxf.service.imp.SB_SOA_SOA_ImportOrgBpelInfoSrv" address="/org" />
<!--启动后,访问:http://localhost:8080/ws/org?wsdl 会出现xml那就ok了。ws是我项目名字-->
<!--<jaxws:endpoint id="HelloWorld2" implementor="com.cxf.service.imp.SB_SOA_SOA_ImportEmpBpelInfoSrv" address="/emp" />-->
<!--启动后,访问:http://localhost:8080/ws/emp?wsdl 会出现xml那就ok了。ws是我项目名字-->
</beans>