cxf之基于servlet容器的服务程序demo

前面已经介绍了基于spring容器的服务程序,这边介绍主要基于servlet容器的服务程序。本人使用的tomcat版本为7.0。

关于服务接口及其实现代码这边不做列出,参照前面博文。

项目类型为dynamic web project。当然项目还要加入cxf依赖的jar包。

1、src下新建spring配置文件servlet/spring.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:http-conf="http://cxf.apache.org/transports/http/configuration"
	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/transports/http/configuration
	http://cxf.apache.org/schemas/configuration/http-conf.xsd
	http://cxf.apache.org/jaxws
	http://cxf.apache.org/schemas/jaxws.xsd">
	
        <!--引入cxf基础配置-->
	<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"/>
	
	<jaxws:endpoint
		id="HelloWorld" implementor="demo.cxf.helloworld.HelloWorldImpl" 
		address="/HelloWorld"/>

</beans>
可以看到address有了变化。

2、配置web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>jax-ws</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
<!--配置spring-->
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>classpath:servlet/spring.xml</param-value>
  </context-param>
  
  <listener>
  	<listener-class>
  		org.springframework.web.context.ContextLoaderListener
  	</listener-class>
  </listener>
  
<!--配置cxf-->
  <servlet>
  	<servlet-name>CXFServlet</servlet-name>
  	<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  </servlet>
  
  <servlet-mapping>
  	<servlet-name>CXFServlet</servlet-name>
  	<url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  
</web-app>
3、发布项目并启动tomcat,访问: http://localhost:8080/jax-ws/services/HelloWorld?wsdl

cxf之基于servlet容器的服务程序demo_第1张图片

你可能感兴趣的:(spring,javaee,servlet,wsdl,instance)