【Spring_WebService(CXF)】环境的搭建以及服务的暴露

来源:互联网 发布:linux拷贝目录命令 编辑:程序博客网 时间:2024/06/02 02:06

一、环境版本介绍:

1.Spring 3.2

2.CXF 2.6.13

二、Jar包的引入:

1.Spring Jar包的引入(由于项目中使用到了Spring的诸多功能,所以选择全部引入):

2.CXF 相关Jar包的引入:

三、环境的具体配置

-----Web.xml------

1.web.xml 配置文件加载Spring上下文容器

<!-- 加载Spring容器配置 --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
2.web.xml 设置Spring加载容器配置的文件路径
<!-- 设置Spring容器加载配置文件路径 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath*:spring-service.xml</param-value></context-param><listener><listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class></listener>
3.web.xml指定CXF Web Service所使用的类
<!-- 指定CXF Web Service所使用的类 --><servlet><servlet-name>CXFService</servlet-name><servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class></servlet>
4.web.xmlWeb Service访问路径映射
<!-- Web Service访问路径映射 --><servlet-mapping><servlet-name>CXFService</servlet-name><url-pattern>/*</url-pattern></servlet-mapping>
-----spring-service.xml------

这段只呈现Logging方法暴露的配置,可根据该配置自行仿写

1.CXF,SOAP XML配置的引入

<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" />
2.业务接口添加注解暴露Service

@WebService@SOAPBinding(style = Style.RPC)public interface LoggingService extends LoggingDao {}
PS:由于我的业务方法来自继承的DAO数据操作类,所以该接口中无方法,你可以直接写一个接口并添加上方法来暴露

3.Service的注入

<!-- 日志Service注入 --><bean id="loggingServiceImpl" class="com.vzr.service.impl.LoggingServiceImpl"><property name="loggingDaoImpl" ref="loggingDaoImpl" /></bean>
PS:这里的loggingDaoimpl,前提是需要你有该DAO的接口注入才能引用

4.Service的访问URI设置

<!-- 暴露LoggingService --><jaxws:server id="loggingService" serviceClass="com.vzr.service.LoggingService"address="/logging"><jaxws:serviceBean><ref bean="loggingServiceImpl" /></jaxws:serviceBean></jaxws:server>
PS:这里的address属性是指在浏览器当中可通过该路径直接访问暴露业务接口的WSDL文档

---对暴露的接口进行访问---

把Web项目发布后即可在浏览器中进行访问,我用的Apache Tomcat

URI:http://localhost:8080/RightHere/logging?wsdl


这样就算业务接口暴露成功了,熟悉WSDL的同学们应该很熟悉这个文档。

如果对WSDL不太熟悉的同学,可以去W3SCHOOL进行学习,想要调用传送数据还需要学习SOAP。

介绍就到这里,欢迎检漏回复。

0 0
原创粉丝点击