@Configuration
@MapperScan({"com.xxxx.**.mapper*", "${mybatis.scan.pkg1:com.temp1.**.mapper*}",
"${mybatis.scan.pkg2:com.temp2.*.mapper*}"})
public class MybatisConfig {
}
/**
* Get the Environment from the given registry if possible, otherwise return a new
* StandardEnvironment.
*/
private static Environment getOrCreateEnvironment(BeanDefinitionRegistry registry) {
Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
if (registry instanceof EnvironmentCapable) {
return ((EnvironmentCapable) registry).getEnvironment();
}
return new StandardEnvironment();
}
配置如下:
在application.yml中注入属性:
发现实际不生效。
经过代码跟踪: Spring在处理这个包转换时 位置在:org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider#resolveBasePackage
这个getEnvironment的属性来源于:org.springframework.context.annotation.ClassPathBeanDefinitionScanner#getOrCreateEnvironment
根原因为: tk.mybatis.spring.annotation.MapperScannerRegistrar
建议修改为:
或者,调用