天天看點

spring mvc mybatis 配置

<!-- 加載應用屬性執行個體,可通過  @Value("#{APP_PROP['jdbc.driver']}") String jdbcDriver 方式引用 -->
<util:properties id="APP_PROP" location="classpath:db.properties" local-override="true"/>
 	<!-- MyBatis begin -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="typeAliasesPackage" value="com.becom"/>
    <property name="typeAliasesSuperType" value="com.becom.common.persistence.BaseEntity"/>
    <property name="mapperLocations" value="classpath:/mappings/**/*.xml"/>
	<property name="configLocation" value="classpath:/mybatis-config.xml"></property>
</bean>
<!-- 掃描basePackage下所有以@MyBatisDao注解的接口 -->
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    <property name="basePackage" value="com.becom"/>
    <property name="annotationClass" value="com.becom.common.persistence.annotation.MyBatisDao"/>
</bean>
   <!-- 定義事務 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	<property name="dataSource" ref="dataSource" />
</bean>

<!-- 配置 Annotation 驅動,掃描@Transactional注解的類定義事務  -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<!-- MyBatis end -->
           

繼續閱讀