1.创建类
2.接口编写
package com.fan; import javax.jws.WebService; @WebService
public interface IHelloWorld {
void SayHi(String str);
}// end
3.实现类编写
package com.fan; import javax.jws.WebService; import org.springframework.stereotype.Service; @Service("RHelloWorld")
@WebService(endpointInterface = "com.fan.IHelloWorld")
public class RHelloWorld implements IHelloWorld { public void SayHi(String str) {
// TODO Auto-generated method stub
System.out.println("SayHi:" + str);
} }// end
4.web配置文件编写
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Fan</display-name>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<display-name>CXFServlet</display-name>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>(ps:编写路径)
</servlet-mapping> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:beans.xml(ps:beans配置文件)
</param-value>
</context-param>
</web-app>
5.编写beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.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-servlet.xml"/>
<context:component-scan base-package="com.fan" />
<jaxws:endpoint id="appWsServer" implementor="#RHelloWorld" address="/appWsServer"/>(ps:实现类) </beans>
6.关键步骤,导入所需要的包
暂时没有精选最少导入哪些包,这里是我导入的包。
7.验证路径
http://localhost:8888/MyWebService/appWsServer?wsdl
请大神将需要的包给我精简一下。