代碼片段:配置Spring和Mybatis整合的applicationContext-mybatis文件

代碼片段,用於配置Spring和Mybatis整合的applicationContext-mybatis文件,直接修改其中的配置即可

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

	<!-- 配置SqlSessionFactory -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 定義數據源 -->
		<property name="dataSource" ref="dataSource"/>
		<!-- 設置mybatis-config.xml路徑 -->
		<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
		<!-- 設置別名包 -->
		<property name="typeAliasesPackage" value="cn.tineaine.summer.manage.entity"/>
		<!-- 設置mapper.xml -->
		<property name="mapperLocations" value="classpath:mybatis/mappers/*.xml"/>
	</bean>
	
	<!-- 定義Mapper接口掃描器 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- 掃描mapper包 -->
		<property name="basePackage" value="cn.tineaine.manage.mapper"/>
	</bean>
</beans>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章