spring boot-使用@EnableConfigurationProperties

spring boot-使用@EnableConfigurationProperties

問題

在引入多數據源整合mybatis時,所以 mybatis-spring-boot-starter中很多自動裝配都失效,但是複用一些 yml 文件中配置文件對應的javaBean,如 MybatisProperties,

mybatis:
  type-aliases-package: com.xxx.bootrdc.**.persist.domain
  configuration:
    map-underscore-to-camel-case: true

如果直接依賴注入的話,是沒有用的,如下:


@Configuration
public class MybatisConfiguration{
	@Autowired
	private MybatisProperties properties;

}

解決方案

那麼就可以使用EnableConfigurationProperties註解了:


@EnableConfigurationProperties(MybatisProperties.class)
@Configuration
public class MybatisConfiguration{


	@Autowired
	private MybatisProperties properties;
}

這樣的話,就可以直接複用 MybatisProperties

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章