cxf与springmvc集成

最近,在学习cxf,想在原来的springmvc中集成,按照网上信息配置,程序正常启动,但是一直访问不到这个webservice服务,特地记录一下,集成过程中需要注意的点。

1.springmvc是通过org.springframework.web.servlet.DispatcherServlet来启动的,cxf是通过org.apache.cxf.transport.servlet.CXFServlet来启动的,CXFServlet中获取content时需要由org.springframework.web.context.ContextLoaderListener提供的content,所以需要springmvc中spring公共部分拆出xml用ContextLoaderListener来加载,mvc部分使用DispatcherServlet来加载

原文件springmvc.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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">

	<context:component-scan base-package="com.employ"/>

	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/page/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>
	<bean class="org.springframework.context.support.ResourceBundleMessageSource"
		id="messageSource" >
		<property name="basename" value="i18n"></property>
	</bean>
	
	<!-- 关联 properties 文件 -->
	<context:property-placeholder location="classpath:db.properties" />
	<!-- 数据源 -->
	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource"
		p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
		p:username="${jdbc.username}" p:password="${jdbc.password}" />
	<!-- class: 指定用来创建 sqlSession 的工厂 dataSource-ref: 使用的数据源 typeAliasesPackage: 
		自动扫描的实体类包 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
		p:dataSource-ref="dataSource" p:typeAliasesPackage="com.employ.entry" />
	<!-- class : 指定自动扫描 xxxMapper.xml 映射文件的类 basePackage: 自动扫描的配置包 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
		p:basePackage="com.employ.mapper" p:sqlSessionFactoryBeanName="sqlSessionFactory" />
	<!-- 事务管理 -->
	<bean id="txManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
		p:dataSource-ref="dataSource" />
	<tx:annotation-driven transaction-manager="txManager" />
	
</beans>
拆分成spring-mybatis.xml 和spring-mvc.xml

spring-mybatis.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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">

	<context:component-scan base-package="com.employ"/>
	<bean class="org.springframework.context.support.ResourceBundleMessageSource"
		id="messageSource" >
		<property name="basename" value="i18n"></property>
	</bean>
	
	<!-- 关联 properties 文件 -->
	<context:property-placeholder location="classpath:db.properties" />
	<!-- 数据源 -->
	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource"
		p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
		p:username="${jdbc.username}" p:password="${jdbc.password}" />
	<!-- class: 指定用来创建 sqlSession 的工厂 dataSource-ref: 使用的数据源 typeAliasesPackage: 
		自动扫描的实体类包 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
		p:dataSource-ref="dataSource" p:typeAliasesPackage="com.employ.entry" />
	<!-- class : 指定自动扫描 xxxMapper.xml 映射文件的类 basePackage: 自动扫描的配置包 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
		p:basePackage="com.employ.mapper" p:sqlSessionFactoryBeanName="sqlSessionFactory" />
	<!-- 事务管理 -->
	<bean id="txManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
		p:dataSource-ref="dataSource" />
	<tx:annotation-driven transaction-manager="txManager" />
</beans>

spring-mvc.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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"  
	xmlns:mvc="http://www.springframework.org/schema/mvc"  
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
	<context:component-scan base-package="com.employ" /> 
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/page/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>
</beans>

2.拆分过程中需要注意xml文件中  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 是必须的


参考资料:cxf与springmvc No services find
参考资料:http://blog.csdn.net/weu135/article/details/13016343
参考资料:Spring ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值