构建基于CXF的WebService服务(4)--CXF与SpringMVC集成
发布时间:2020-12-16 23:35:08 所属栏目:安全 来源:网络整理
导读:SpringMVC的配置就不多说了,这个在网上有很多的资料,直接上我web.xml的全部配置 ?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:sche
SpringMVC的配置就不多说了,这个在网上有很多的资料,直接上我web.xml的全部配置 <?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"> <!-- 载入log4j配置文件 --> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:META-INF/log4j.properties</param-value> </context-param> <!--Spring默认刷新Log4j配置文件的间隔,单位为millisecond--> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>60000</param-value> </context-param> <!--Spring log4j Config loader--> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!-- Spring 刷新Introspector防止内存泄露 --> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:META-INF/applicationContext.xml </param-value> </context-param> <!-- springMVC配置 --> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!--Spring的ApplicationContext 载入 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- spring字符过滤器 --> <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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--CXF配置--> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/WebService/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> Spring中的配置(方法一) <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="com.tiamaes.webservice.HelloWorldImpl" address="/HelloWorld" /> Spring中的配置(方法二) <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" /> <bean id="helloWorldImpl" class="com.tiamaes.webservice.HelloWorldImpl"></bean> <jaxws:endpoint id="helloWorld" implementor="#helloWorldImpl" address="/HelloWorld" /> 其中:implementor是实现类,address是地址,配置完之后可以通过 http://localhost:8080/wstest/WebService/HelloWorld?wsdl来方位到webservice 推荐用第二种方法,因为第二种你可以在类中利用spring注入属性,而第一种不可以(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |