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
。完成。