`

cxf在spring中开发步骤(服务端)

阅读更多
1,导入jar 包
              <!-- cxf -->
                
                <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-api</artifactId>
                        <version>2.7.7</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-frontend-jaxws</artifactId>
                        <version>2.7.7</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-bindings-soap</artifactId>
                        <version>2.7.7</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-transports-http</artifactId>
                        <version>2.7.7</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-ws-security</artifactId>
                        <version>2.7.7</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.httpcomponents</groupId>
                        <artifactId>httpcore</artifactId>
                        <version>4.3</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpcore-nio</artifactId>
                    <version>4.3</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpasyncclient</artifactId>
                    <version>4.0-beta4</version>
                </dependency>
                <!-- cxf -->

  2.写接口
package com.sharp.hibernatedemo.ws;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

import com.sharp.hibernatedemo.domain.User;

@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL)
public interface IUserServiceWs
{
        void addUser(User user);
}


3.写实现类
package com.sharp.hibernatedemo.ws.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sharp.hibernatedemo.domain.User;
import com.sharp.hibernatedemo.service.IUserService;
import com.sharp.hibernatedemo.ws.IUserServiceWs;
@Component("userServiceWs")
public class UserServiceWsImpl implements IUserServiceWs
{
        @Autowired
        private IUserService userService;
        public void addUser(User user)
        {
                userService.addUser(user);
        }

}




4.配置spring-ws.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:p="http://www.springframework.org/schema/p"
        xmlns:jaxws="http://cxf.apache.org/jaxws"
        xsi:schemaLocation="http://www.springframework.org/schema/beans                                                 http://www.springframework.org/schema/beans/spring-beans-3.2.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-servlet.xml" />
    <jaxws:server id="userServiceWss"
                serviceClass="com.sharp.hibernatedemo.ws.IUserServiceWs"
                address="/userServiceWs">
                <jaxws:serviceBean>
                        <ref bean="userServiceWs" /> <!-- 和上面的id名字一定不要重复了 -->
                </jaxws:serviceBean>
        </jaxws:server>
</beans>



需要注意的namespace
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	[b]xmlns:jaxws="http://cxf.apache.org/jaxws" [/b]
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:http-conf = "http://cxf.apache.org/transports/http/configuration"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
[b]    http://cxf.apache.org/jaxws 
    http://cxf.apache.org/schemas/jaxws.xsd[/b]
    http://cxf.apache.org/transports/http/configuration    
    http://cxf.apache.org/schemas/configuration/http-conf.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" />
</beans>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics