spring.profiles屬性導致獲取配置失敗

今天啓動項目突然報錯 報錯信息如下

BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.xx.Application]; nested exception is java.util.NoSuchElementException: No value bound




Caused by: java.util.NoSuchElementException: No value bound
	at org.springframework.boot.context.properties.bind.BindResult.get(BindResult.java:56)
	at com.xx.DynamicDataSourceRegister.setEnvironment(DynamicDataSourceRegister.java:46)

通過上面的信息判斷爲獲取應用配置信息失敗

BindResult<Properties> bindResult = binder.bind("spring.datasource", Properties.class);
Properties propertyResolver = (Properties)bindResult.get();




 public T get() throws NoSuchElementException {
        if (this.value == null) {
            throw new NoSuchElementException("No value bound");
        } else {
            return this.value;
        }
    }

通過上面的代碼得知獲取不到spring.datasource配置 但是明明配置了該屬性 而且昨天都好好的
看了半天冒看出問題 還是 偶然改了下別的環境後啓動沒報錯 經過對比分析最後發現具體環境下的配置文件profiles錯誤
 

application.yml
spring:
  profiles:
    active: xx

application-xx.yml
spring:
  profiles: yy

把yy改成xx既可  

提示還是不夠友好啊

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