abel533 / MyBatis-Spring-Boot

Spring Boot集成MyBatis的基础项目
3.37k stars 1.59k forks source link

配置tk.mybatis.spring.mapper.MapperScannerConfigurer后spring-mybatis中的ClassPathMapperScanner有warn日志 #61

Open helloworldtang opened 7 years ago

helloworldtang commented 7 years ago

使用tk.mybatis.spring.mapper.MapperScannerConfigurer的setBasePackage配置了Mapper接口, 但org.mybatis.spring.mapper.ClassPathMapperScanner#doScan方法会报 No MyBatis mapper was found in '" + Arrays.toString(basePackages) + "' package. Please check your configuration."

怎么解决这个问题呢

abel533 commented 7 years ago

把你配置贴出来。。错误信息也提供完整的。

helloworldtang commented 7 years ago

因为是双数据源,无法使用mybatis的starter

所以:

···xml

pager

pagehelper.helperDialect=mysql pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql

    <!--pagehelper-->
    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.1.2</version>
    </dependency>

    <!--mapper-->
    <dependency>
        <groupId>tk.mybatis</groupId>
        <artifactId>mapper-spring-boot-starter</artifactId>
        <version>1.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.4.4</version>
    </dependency>

    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>1.3.1</version>
    </dependency>

```java
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setBasePackage("com.car.domain.mapper");
        Properties properties = new Properties();
        properties.setProperty("notEmpty", "false");
        properties.setProperty("IDENTITY", "MYSQL");
        mapperScannerConfigurer.setProperties(properties);
        mapperScannerConfigurer.setMarkerInterface(BaseMapper.class);
        return mapperScannerConfigurer;
    }
abel533 commented 7 years ago

是不是两个 sqlSessionFactory ?最新版本starter支持多个。

helloworldtang commented 7 years ago

一个sqlSessionFactory. 数据源使用org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource进行切换

当时采用这种aop方式,觉得代码比较简洁。

但是日志总是出现warn,觉得很不爽

abel533 commented 7 years ago

调试看看从哪儿出来的警告,看看产生警告的原因。

helloworldtang commented 7 years ago

org.mybatis.spring.mapper.ClassPathMapperScanner#doScan方法会报 No MyBatis mapper was found in '" + Arrays.toString(basePackages) + "' package. Please check your configuration."

上面这个class里的doScan方法中打印的

abel533 commented 7 years ago

你basePackages里面有吗?如果没有就忽略警告。。

helloworldtang commented 7 years ago

basePackages配置在Java config里面了: @Bean public MapperScannerConfigurer mapperScannerConfigurer() { MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer(); mapperScannerConfigurer.setBasePackage("com.car.domain.mapper");

报错的package是Application.java文件所在的package

hezuchao commented 7 years ago

楼主我也碰到这个问题了,请问你们是怎么解决这个问题的

BlackChen277 commented 6 years ago

我也碰到了