tomcat中的简单CXF webservice
tomcat中使用cxf做的webservice服务端,需要一个sevlet来管理webservice服务端
需要在web.xml中加入如下代码
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
cn.jsprun.ws.StartUpListener
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
StartUpListener类要继承CXFNonSpringServlet:
package cn.jsprun.ws; import javax.servlet.ServletConfig; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; import javax.xml.ws.Endpoint; import org.apache.cxf.transport.servlet.CXFNonSpringServlet; public class StartUpListener extends CXFNonSpringServlet{ @Override public void loadBus(ServletConfig servletConfig) { super.loadBus(servletConfig); System.out.println("web service start"); HotTopicImpl implementor = new HotTopicImpl(); String address = "/hotTopic.do"; Endpoint.publish(address, implementor); System.out.println("web service started"); } }
这样webservice服务就建立了
启动tomcat,在url中输入http://localhost:8080/mytest/service/hotTopic.do?wsdl来验证是否webservice是否创建成功

浙公网安备 33010602011771号