概述
首先到官网上下载CXF整套包导入项目中,另外CXF2.2以下版本需要jdk1.5而CXF2.3以上需要jdk1.6
axis2发布服务:
编写要发布服务的service
public class HelloService {
public String getInfo(String name){
return "姓名:"+name;
}
}
web.xml配置servlet
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
这里的<url-pattern>/services/*</url-pattern>不能换成其它的,否则会找不到相应的WebService。
配置web.xml中bean文件
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-service-bean.xml
</param -value>
</param -name>
</context-param>
spring-service-bean.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="HelloService" class="com.*.*.HelloService">
</bean>
</beans>
发布文件services.xml,放在services/META-INF里面
<service name="HelloService">
<parameter name="ServiceObjectSupplier" locked="false">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>
<parameter name="SpringBeanName" locked="false">HelloService</parameter>
<operation name="getInfo">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
<!--不需要发布的-->
<excludeOperations>
<operation>方法名称</operation>
</excludeOperations>
<!--如果引用module要在此注明,本文没有引用-->
<module ref="name" />
</service>
发布项目可以运行了,客户端调用就不在赘述了,上篇博客有。
CXF集成spring发布webservice
发布service的类如上
web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>cxfwebservice</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<display-name>CXFServlet</display-name>
<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>/webservices/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<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-2.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<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" />
<!-- 发布服务 -->
<bean id="hello" class="com.*.*service" />
<jaxws:endpoint id="helloWorld" implementor="#hello"
address="/HelloWorld">
</jaxws:endpoint>
</beans>
运行项目就发布成功了,客户端调用请参照上篇博客。
最后
以上就是苹果水杯为你收集整理的axis2和CXF集成spring发布服务的全部内容,希望文章能够帮你解决axis2和CXF集成spring发布服务所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复