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"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<bean id="heel" class="cn.com.demo.webservice.impl.WebServiceImpl"></bean>
<!--第一种方法 <jaxws:endpoint id="service" address="/webService" implementor="#heel" /> -->
<!-- 第二种方法 -->
<jaxws:server id="service" address="/webService" serviceClass="cn.com.demo.webservice.WebService">
<jaxws:serviceBean>
<bean class="cn.com.demo.webservice.impl.WebServiceImpl"></bean>
</jaxws:serviceBean>
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:server>
</beans>
WebService.java
package cn.com.demo.webservice;
import java.util.List;
import cn.com.demo.entity.User;
@javax.jws.WebService<pre name="code" class="java">//必须写
public interface WebService{public String listSele(String name);}
WebServiceImpl.java
package cn.com.demo.webservice.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import cn.com.demo.entity.User;
import cn.com.demo.service.IUserService;
import cn.com.demo.webservice.WebService;
@javax.jws.WebService(endpointInterface="cn.com.demo.webservice.WebService")//必须写
public class WebServiceImpl implements WebService
{
@Autowired
private IUserService userService;
@Override
public String listSele(String username)
{
User user=new User();
user.setUserUsername(username);
List<User> list=userService.selectRole(user);
return list.get(0).toString();
}
}
web.xml
<servlet>
<servlet-name>CXFservlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFservlet</servlet-name>
<url-pattern>/WebService/*</url-pattern>
</servlet-mapping>