Spring MVC +Mybatis + Maven 配置之Dao配置

来源:互联网 发布:unity3d碰撞检测代码 编辑:程序博客网 时间:2024/05/07 05:44

        spring dao配置


<?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:util="http://www.springframework.org/schema/util"       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"       xsi:schemaLocation="http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd        http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-3.1.xsd        http://www.springframework.org/schema/util         http://www.springframework.org/schema/util/spring-util-3.1.xsd        http://www.springframework.org/schema/mvc         http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd         http://www.springframework.org/schema/aop         http://www.springframework.org/schema/aop/spring-aop.xsd         http://www.springframework.org/schema/tx         http://www.springframework.org/schema/tx/spring-tx.xsd">    <context:component-scan base-package="cn.kangbao.webapp.db.appmgr"/>    <context:component-scan base-package="cn.kangbao.webapp.db.appmgr.dao"/>    <context:component-scan base-package="cn.kangbao.webapp.db.appmgr.dao.xml"/>    <!-- <aop:aspectj-autoproxy /> -->    <context:annotation-config />    <!--         由于context:component-scan扫描包路径已经包含了自动注入        AutowiredAnnotationBeanPostProcessor、        CommonAnnotationBeanPostProcessor、        PersistenceAnnotationBeanPostProcessor、        RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。          因此无需再配置context:annotation-config(context:annotation-config实现的便是注入这四个bean)    -->        <context:component-scan base-package="com.ps007.*.*,com.rrtong.*.*"/>    <bean id="rrtongSqlSessionFactory" name="rrtongSqlSessionFactory"  class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="rrtongDataSource" />        <property name="configLocation" value="classpath:setup/mybatis-config-rrtong.xml" />    </bean>    <bean id="rrtongMapperScannerConfigurer" name="rrtongMapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">        <property name="sqlSessionFactory" ref="rrtongSqlSessionFactory" />        <property name="basePackage" value="com.rrtong.rrt.*.dao" />    </bean>    <bean id="centerSqlSessionFactory" name="centerSqlSessionFactory"  class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="centerDataSource" />        <property name="configLocation" value="classpath:setup/mybatis-config-center.xml" />    </bean>    <bean id="centerMapperScannerConfigurer" name="centerMapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">        <property name="sqlSessionFactory" ref="centerSqlSessionFactory" />        <property name="basePackage" value="com.ps007.*.dao" />    </bean>    <!-- 创建SqlSessionFactory,同时指定数据源 -->     <bean name="webappsqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"         p:dataSource-ref="webappdataSource"         p:configLocation="classpath:mybatis/webappsqlmapconfig.xml">         <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->        <property name="mapperLocations" value="classpath*:cn/kangbao/webapp/db/appmgr/**/*Mapper.xml" />     </bean>         <bean id="webappsqlSession" class="org.mybatis.spring.SqlSessionTemplate">         <constructor-arg index="0" ref="webappsqlSessionFactory"/>         <constructor-arg index="1" value="BATCH"/>         <!-- 如果想要进行批量操作可加入这个属性 -->     </bean></beans>

0 1