首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

CXF+mybatis+Spring 配备

2012-12-25 
CXF+mybatis+Spring 配置CXF的server端配置 ?首先配置web.xml?servlet servlet-namecxfServlet/servl

CXF+mybatis+Spring 配置

CXF的server端配置 ?首先配置web.xml?

<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>/cxf/*</url-pattern> </servlet-mapping> 

?applicationContext.xml和myBatisConfig.xml文件都放在了src目录下

其中applicationContext.xml中的配置

在配置文件头添加CXF的配置xmlns:jaxws="http://cxf.apache.org/jaxws"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" /><!-- WebService 服务端配置信息 --><bean id="jsmService" /><jaxws:endpoint id="getUser" implementor="#jsmService"address="/JsmWeb"></jaxws:endpoint>

?

在springmvc-servlet.xml文件中导入applicationContext.xml文件

?

<import resource="classpath:/applicationContext.xml"/>
?

CXF客户端applicationContext.xml中的配置?:

?

在配置文件头添加CXF的配置xmlns:jaxws="http://cxf.apache.org/jaxws"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" /><!-- WebService 客户端配置信息 --><jaxws:client id="JsmWebClient" service/>

?服务器端使用CXF

@Override    public String updateUserState(String userId)    {        // 初始化userDao        UserDao userDao = (UserDao)Global.getObject(UserDao.class);                // 修改用户在线状态为离线        userDao.updateUserState(0, userId);                return Global.SUCCESS;    }
?客户端使用CXF 把服务端的接口打成jar包放到客户端调用接口即可

热点排行