本文主要是介绍SpringMVC与WebService服务端,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
###pom.xml【maven】
<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><cxf-version>3.1.7</cxf-version> </properties>
<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>
###web.xml
<!-- webService CXF -->
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/webService/*</url-pattern>
</servlet-mapping>
###applicationContext.xml
<import resource="classpath:applicationContext-cxf.xml" />
###applicationContext-cxf.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-3.2.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"><jaxws:endpoint id="testwsService" implementor="com.wjh.test.sync.service.impl.testwsServiceImpl" address="/testwsService" /></beans>
或者
<!-- JAX-WS 标准发布模式 --> <jaxws:server id="auditService" address="/auditService"><jaxws:serviceBean><ref bean="auditServiceImpl"/></jaxws:serviceBean></jaxws:server>
-------------------------------------------------------------------------
import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; @WebService public interface TestwsService { @WebResult(name="result")public String getInfo(@WebParam(name = "bsid")String bsid, @WebParam(name = "boid")String boid); }
----------------------------------------------------------------------------------------
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; @WebService(endpointInterface="com.wjh.test.sync.service.TestwsService") public class TestwsServiceImpl implements TestwsService { @Autowired private CommonService commonService;@WebResult(name="result")public String getInfo(@WebParam(name = "bsid")String bsid, @WebParam(name = "boid")String boid) {return commonService.getInfo(bsid, boid);} }
最终:
http://localhost:8080/webService/testwsService?wsdl
这篇关于SpringMVC与WebService服务端的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!