CXF spring 整合

来源:互联网 发布:java socket连接 编辑:程序博客网 时间:2024/06/05 19:53

1、准备jar包:

 

2、web.xml配置

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/classes/applicationContext-server.xml</param-value>
  </context-param>
  <listener>   
  <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>
  <listener>      
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  </listener>
  <servlet>   
  <servlet-name>CXFService</servlet-name>   
  <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  </servlet>
  <servlet-mapping>   
  <servlet-name>CXFService</servlet-name>   
  <url-pattern>/service/*</url-pattern>
  </servlet-mapping>
   <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

 

3、cxf配置文件:applicationContext-server.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:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:jaxws="http://cxf.apache.org/jaxws" 
 xsi:schemaLocation="
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-2.5.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="DevNodeWebServiceImpl" class="com.dp.test.DevNodeWebServiceImpl"/>
 <!-- 注意下面的address,这里的address的名称就是访问的WebService的name -->
 <jaxws:server id="NodeWebService" serviceClass="com.test.service.NodeWebService" address="/NodeWebService">   
  <jaxws:serviceBean>       
  <!-- 要暴露的 bean 的引用 -->       
   <ref bean="DevNodeWebServiceImpl"/>   
  </jaxws:serviceBean>   
 </jaxws:server>
</beans>

 

4、接口类:NodeWebService

package com.test.service;

import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@SOAPBinding(style = Style.DOCUMENT)
public interface NodeWebService
{
 public String getSubNodeInfo();
}

 

5、实现类

package com.test.dao;

import javax.jws.WebService;

import org.springframework.web.util.HtmlUtils;

import com.test.service.NodeWebService;

@WebService
public class DevNodeWebServiceImpl implements NodeWebService
{

 public String getSubNodeInfo()
 {
    return "hello";

 }
 
}

6、输入http://localhost:8080/cxf/service/如果出现下面的信息。部署成功。cxf是我的工程名.


 

 

 

 

0 0
原创粉丝点击