在配置MapperScannerConfigurer的時候一直提示我以下信息,雖然不影響代碼運行可是看着很煩,仔細看提示信息才發現,它再說若是隻有一個數據源的話你不須要配置SqlSessionFactory。因此把提示報差的那航配置文件註釋掉就行了。spring
錯誤原文:mybatis
Specifies which SqlSessionFactory to use in the case that there is more than one in the spring context. Usually this is only needed when you
have more than one datasource. Note bean names are used, not bean references. This is because the scanner loads early during the
start process and it is too early to build mybatis object instances.
【個人配置文件】app
<!-- 使用自動掃描建立mapper bean --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.lcy.mapper" /> <property name="SqlSessionFactoryBeanName" value="SqlSessionFactory" /> <property name="annotationClass" value="org.springframework.stereotype.Repository" /> </bean>
【正確的配置文件】ui
<!-- 使用自動掃描建立mapper bean --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.lcy.mapper" /> <property name="annotationClass" value="org.springframework.stereotype.Repository" /> </bean>
多個數據源配置參見:https://blog.csdn.net/tan554334064/article/details/52188885