天天看點

spring boot @value 取不到.properties的值

最近我們組在為别的組提供api接口,需要通過@value取到properties裡配置的逾時時間,結果怎麼設定都取不到,而通過@ConditionalOnProperty或者@ConfigurationProperties,都可以成功取到,最後在堅持不懈的努力下,找到了原因,因為那個項目用到了shiro,而shiro有個配置和@value正好沖突了。

@Bean
public  LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
	return new LifecycleBeanPostProcessor();
}
           

最後通過自定義的properties,然後通過

@ConfigurationProperties(prefix = "prefix", locations = "classpath:config.properties")

加載進來,如果是yml的話參照spring官網的https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-yaml-shortcomings

最後

至于為什麼會沖突我還沒時間研究。。先埋個坑,以後在填。

繼續閱讀