您的位置:首页 > 编程语言 > Java开发

spring与cxf整合开发webservice服务接口

2017-08-09 13:48 489 查看
1、pom.xml文件中加入最新的jar:

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>


2、编写webservice接口:

import javax.jws.WebMethod;
import javax.jws.WebService;

/**
* Created by ssl on 2017/8/8.
*/
@WebService
public interface VerifyWS {
@WebMethod
ResultInfo verity(VerifyInfo verifyInfo);
}


3、编写实现VerifyWS接口的类:

import com.szitrus.smp.gateway.service.GatewayService;
import com.szitrus.smp.service.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

/**
* Created by ssl on 2017/8/8.
*/
public class VerifyWSImpl implements VerifyWS {
@Autowired
private AppService appService;
@Autowired
private GatewayService gatewayService;
@Value("#{APP_PROP['local.seal.dir']}")
private String local_seal_dir;

@Override
public ResultInfo verity(VerifyInfo verifyInfo) {
ResultInfo resultInfo = new ResultInfo();
resultInfo.setCode("1");//0验证成功,1验证失败
resultInfo.setMessage("验证失败,服务端异常");
//编写业务逻辑···
//```````
return resultInfo;
}
}


4、recourse目录下,新建applicationContext-webservice.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.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml"/>
<jaxws:endpoint id="makeSealService" implementor="com.szitrus.smp.gateway.webservice.seal.MakeSealWSImpl"
address="/makeSealService"/>
<jaxws:endpoint id="verifyService" implementor="com.szitrus.smp.gateway.webservice.verify.VerifyWSImpl"
address="/verifyService"/>
</beans>


5、web.xml文件中,增加如下配置:

<!-- webservice -->
<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>/webservice/*</url-pattern>
</servlet-mapping>


6、启动服务,浏览器输入:
http://127.0.0.1:8080/[项目名称]/webservice/verifyService?wsdl
。完成。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  web service spring cxf