先記錄一下,后期補充配置原因
原先的spring3.X(struts2)的時候配置cxf2.x沒問題,基本就是在context.xml中加入
<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"/>
這三個文件即可。
后期框架為springmvc4.3(mybatis),這時候cxf的版本已經迭代到3.2.4了,我們查看一下這個最新版本的編譯發現是jdk8了,部署在我們的jdk7下回報錯,所以講版本,目前我用的是
spring4.3+mybatis3.4+cxf3.1.6
主要說一配置文件的事情(spring-mybatis.xml,spring-mvc.xml,cxf-servlet.xml,web.xml)
cxf-servlet.xml文件的位置要放到應用上下文的加載位置,不能放到servlet的加載位置,也就是說
1、可以放到咱們的WEB-INF下(編譯后類的根目錄,在webapp下)
2、可以放到web.xml下的<context-param>,如:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-mybatis.xml,classpath:spring/cxf-servlet.xml</param-value>
</context-param>
3、可以直接在spring-mybatis.xml中import一下,這樣應用啟動時候,在應用環境加載mybatis的時候,它一起加載
<import resource="cxf-servlet.xml"/>
總而言之,保證在應用的加載路徑下即可
我猜這樣的原因,是cxf的一些配置調用是全局的上下文而不是servlet域的(每個servlet都有自己的上下文,他們共享javabean),這個后期考證后在這里補上
發一下cxf的maven和配置:
maven:
<!-- cxf begin -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.6</version>
</dependency>
<!-- cxf end -->
cxf-servlet.xml內容:
<?xml version="1.0" encoding="UTF-8"?>
<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:endpoint id="webService" implementor="com.cotton.fiber.webservice.FiberWebServiceImpl" address="/webService"></jaxws:endpoint>
</beans>
