JAX-WS与Spring Annotation配合中的关键

@WebService(targetNamespace = "http://xxx.cn/tp")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class PeopleI extends SpringBeanAutowiringSupport{
	@Autowired
	private IPeopleService peopleService;

	@WebMethod
	@WebResult(partName = "write")
	public WriteResponse write(@WebParam(name = "serviceId", partName = "serviceId") String serviceId,
			@WebParam(name = "message", partName = "message") String message,
			@WebParam(name = "encrypted", partName = "encrypted") boolean encrypted) {
		return peopleService.write(serviceId, message, encrypted);
	}
}

 WS服务类要继承SpringBeanAutowiringSupport后才能使用@Autowired。

 

 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">

	<!-- 默认的spring配置文件是在WEB-INF下的applicationContext.xml -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	

	<listener>
		<listener-class>
			com.sun.xml.ws.transport.http.servlet.WSServletContextListener
		</listener-class>
	</listener>
	
	<!-- People WebService -->
	<servlet>
		<servlet-name>PeopleIService</servlet-name>
		<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>PeopleIService</servlet-name>
		<url-pattern>/peoplei</url-pattern>
	</servlet-mapping>
	
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>

web.xml中对ContextLoaderListener的声明一定要在WSServletContextListener的前面。

 

 sun-jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"	version="2.0">
	<endpoint name="PeopleIService" implementation="cn.xxx.PeopleI" url-pattern="/peoplei" />
</endpoints>

你可能感兴趣的:(JAX-WS与Spring Annotation配合中的关键)