由于在MapperScannerConfigurer的bean 优先于@value,导致@value取出来的时候都是null,所以只能使用Environment 来获取值
import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; @Configuration public class MyBatisConfig { @Value("${mybatis.mapper.basePackage}") private String basePackage; @Bean public MapperScannerConfigurer mapperScannerConfigurer(Environment environment) {
environment.getProperty("xxx.xxxx") MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer(); // 如果需要使用环境变量中的值,可以这样设置 mapperScannerConfigurer.setBasePackage(environment.getProperty("mybatis.mapper.basePackage")); // 其他配置... return mapperScannerConfigurer; } }
标签:BasePackage,springframework,Environment,applicayion,mapperScannerConfigurer,org, From: https://www.cnblogs.com/zhian/p/18344867