1. 程式人生 > >SpringMVC與WebService服務端

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