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>
?
轉載于:https://www.cnblogs.com/sss-justdDoIt/p/9300210.html
總結
以上是生活随笔為你收集整理的java - springmvc整合cxf发布webservice的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: idea查看类和方法的结构图
- 下一篇: m.555lu.co list.php,