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" class="com.a.webservice.impl.JsmWebServiceImpl" />
<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" serviceClass="com.blingtel.webservice.JsmWebService"
address="http://localhost:8080/SafeManageSystem/cxf/JsmWeb" />
服务器端使用CXF
@Override
public String updateUserState(String userId)
{
// 初始化userDao
UserDao userDao = (UserDao)Global.getObject(UserDao.class);
// 修改用户在线状态为离线
userDao.updateUserState(0, userId);
return Global.SUCCESS;
}
客户端使用CXF 把服务端的接口打成jar包放到客户端调用接口即可
页:
[1]