Home  >  Article  >  Java  >  How does springboot specify the mapper file scanning path in mybatis?

How does springboot specify the mapper file scanning path in mybatis?

WBOY
WBOYforward
2023-05-17 22:25:522987browse

Specify the mapper file scan path in mybatis

All mapper mapping files

mybatis.mapper-locations=classpath*:com/springboot/mapper/*.xml

or the mapper mapping file under resource

mybatis.mapper-locations=classpath*:mapper/**/*.xml

How to configure multiple scan paths in mybatis

Baidu got it, but it’s very messy. Let’s sort it out a little:

Recently dismantled the project and encountered a small problem. I’ll record it a little bit:

<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- 自动扫描mapping.xml文件 -->
        <property name="mapperLocations" value="classpath*:com/**/mapping/*.xml"></property>
    </bean>
 
    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.xxx.dao" />
        <!--<property name="basePackage" value="com.xxx.dao,com.yyyy.dao" />-->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

The above is the detailed content of How does springboot specify the mapper file scanning path in mybatis?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete