没看过那个例子的朋友,这里把例子写出来
HelloWorld.java
package demo.hw.server;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
String sayHi(String text);
}HelloWorldImpl.java
package demo.hw.server;
import javax.jws.WebService;
@WebService(endpointInterface = "demo.hw.server.HelloWorld", serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld { public String sayHi(String text) {
return "Hello " + text;
}
}Server.java
package demo.hw.server;import javax.xml.ws.Endpoint;public class Server { protected Server() throws Exception {
// START SNIPPET: publish
HelloWorldImpl implementor = new HelloWorldImpl();
String address = "http://localhost:8080/helloWorld";
Endpoint.publish(address, implementor);
// END SNIPPET: publish
}
}
部署后会自动生成web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>cxf</display-name>
<description>cxf</description>
<servlet>
<servlet-name>cxf</servlet-name>
<display-name>cxf</display-name>
<description>Apache CXF Endpoint</description>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>最后在浏览器中输入URL,提示No service was found.但不报错