标签:data classpath bin ati service stat shm factory boot
spring boot整合mybatis-plus使用mysql和Oracle多数据源的时候,遇到如下问题:
mybatis-plus今天遇到一个问题,就是mybatis 没有读取到mapper.xml 文件。
特此记录一下,问题如下:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.husy.mapper.SystemUserMapper.findUserByName at com.baomidou.mybatisplus.core.override.MybatisMapperMethod$SqlCommand.<init>(MybatisMapperMethod.java:242) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:54) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambda$cachedMapperMethod$0(MybatisMapperProxy.java:65) at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.cachedMapperMethod(MybatisMapperProxy.java:65) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:60) at com.sun.proxy.$Proxy72.findUserByName(Unknown Source) at com.husy.service.impl.SystemUserServiceImpl.findUserByName(SystemUserServiceImpl.java:23)
首先我放xml的包的是没问题的,而是引入的架包和配置问题,问题配置如下:
mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.msl.moniter.entity
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-core</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-autoconfigure</artifactId>
<version>2.1.0</version>
</dependency>
@Configuration public class MybatisPlusConfig { @Autowired private DataSource dataSource; @Autowired private MybatisProperties properties; @Autowired private ResourceLoader resourceLoader = new DefaultResourceLoader(); @Autowired(required = false) private Interceptor[] interceptors; @Autowired(required = false) private DatabaseIdProvider databaseIdProvider; /** * mybatis-plus分页插件 */ @Bean public PaginationInterceptor paginationInterceptor() { PaginationInterceptor page = new PaginationInterceptor(); page.setDialectType("mysql"); return page; } /** * 这里全部使用mybatis-autoconfigure 已经自动加载的资源。不手动指定 * 配置文件和mybatis-boot的配置文件同步 * @return */ @Bean public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() { MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean(); mybatisPlus.setDataSource(dataSource); mybatisPlus.setVfs(SpringBootVFS.class); if (StringUtils.hasText(this.properties.getConfigLocation())) { mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation())); } mybatisPlus.setConfiguration(properties.getConfiguration()); if (!ObjectUtils.isEmpty(this.interceptors)) { mybatisPlus.setPlugins(this.interceptors); } MybatisConfiguration mc = new MybatisConfiguration(); mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class); mybatisPlus.setConfiguration(mc); if (this.databaseIdProvider != null) { mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider); } if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) { mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage()); } if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) { mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage()); } if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) { mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations()); } return mybatisPlus; } }
不知道是造作不正确还是jar问题,如下验证没有通过
经过查阅:
参考:
https://blog.csdn.net/u013234928/article/details/94060733
https://blog.csdn.net/qq_21747795/article/details/81217264
mybatis-plus的 mapper.xml 路径配置的坑
标签:data classpath bin ati service stat shm factory boot
原文地址:https://www.cnblogs.com/Sincerity/p/11990445.html