框架版本:CXF-2.5.9 和 Spring-3.2.1
asm-3.3.1.jar commons-logging-1.1.1.jar cxf-2.5.9.jar neethi-3.0.2.jar wsdl4j-1.6.2.jar xmlschema-core-2.0.3.jar
<servlet> <servlet-name>CXFService</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <!-- 如果有spring mvc --> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFService</servlet-name> <url-pattern>/sysWebservice/*</url-pattern> </servlet-mapping>
头部加入命名空间
xmlns:jaxws="http://cxf.apache.org/jaxws"
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" /> <!-- #xxx 代表引用spring容器中的bean --> <jaxws:endpoint id="helloWorld2" implementorClass="com.lwp.webservice.AddUser2" address="/helloWorld2" implementor="#userwebservice2" />
AddUser2 interface
import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import com.lwp.entity.User; //标记为一个web service @WebService public interface AddUser2 { //@WebParam 自定义方法参数名 public boolean addUser2(@WebParam(name="userObj")User u,int age,String name); public User findAll2(); //自定义方法吗 @WebMethod(operationName="say_good") public String sayGood2(String name); }AddUser2Implement 实现类
import javax.jws.WebService; import org.springframework.stereotype.Service; import com.lwp.entity.User; import com.lwp.webservice.AddUser2; @WebService(endpointInterface="com.lwp.webservice.AddUser2") //注入spring 容器 implementor="#userwebservice2" @Service(value="userwebservice2") public class AddUserImpl2 implements AddUser2 { //@Resource //private BaseHelper baseHelper; public boolean addUser2(User u,int age,String name) { System.out.println(u + "\t" +age +"\t" +name); return false; } public User findAll2() { return new User(1,"admin"); } public String sayGood2(String name) { System.out.println(name+"say good"); return "你好"+System.currentTimeMillis(); } }
开启服务访问wsdl文件,结果如下证明发布成功!