0%

mybtis和mybatis-plus配置时的问题

mybatis和mybatis-plus配置问题

在调研ShardingJdbc做分库分表底层是否适用mybatis的时候,
突然mapper文件扫描不到了。
出现了Property ‘mapperLocations‘ was not specified的bug
初始配置如下

1
2
3
4
5
6
7
8
9
10
mybatis:
type-aliases-package: com.example.demo.domain # ����POJO�����ڰ�·��
mapper-locations: classpath:mapper/*.xml # mapperӳ���ļ�
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
cache-enabled: true
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

因为使用了mybatis-plus所以mybatis-plus也要加上mapper路径.
查看mybatis-plus的locations源码,发现默认在
classpath*:/mapper/**/*.xml下面
需要做修改

1
2
3
4
5
6
7
8
9
10
11
12
13
mybatis:
type-aliases-package: "com.example.demo.box.pojo"
mapper-locations: "classpath:mybatis/mapper/*.xml"
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
cache-enabled: true
check-config-location: true
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:mybatis/mapper/*.xml
type-aliases-package: com.example.demo.box.pojo

mybatis-plus源码↓

1
private String[] mapperLocations = new String[]{"classpath*:/mapper/**/*.xml"};