【Spring MVC】【1】mybatis spring的自动扫描配置

正文:

    <!-- 当有多个数据源时, 自sqlSessionFactory, mapperScannerConfigurer 到 transactionmanager, 都要设置两套id -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.rockbb.facility.common.dao.mapper, com.rockbb.facility.weixin.dao.mapper" />
        <!-- 当只有一个数据源时,这行可以不写. -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSourceLocal" />
        <property name="mapperLocations">
            <list>
                <value>classpath:com/rockbb/facility/common/dao/mapper/*.xml</value>
                <value>classpath:com/rockbb/facility/weixin/dao/mapper/*.xml</value>
            </list>
        </property>
    </bean>

其实后面发现可以用通配符*号。。。

参考博客:

多个mapper location时, mybatis spring的自动扫描配置 - Milton - 博客园
https://www.cnblogs.com/milton/p/4497355.html

猜你喜欢

转载自www.cnblogs.com/huashengweilong/p/10924948.html