Spring开发工具属性

时间:2018-09-04 18:18:55

标签: java spring spring-boot

我正在研究一个从属性文件加载数据库信息的spring-boot程序,到目前为止还可以,但是在进行一些调试时,我发现加载的信息不是来自我的属性文件,而是在某个地方称为“本地开发工具”。

我知道这是因为我有这段代码记录了已加载的所有属性:

 public class PropertiesLogger implements 
      ApplicationListener<ApplicationPreparedEvent> {
private static final Logger log = LoggerFactory.getLogger(PropertiesLogger.class);

private ConfigurableEnvironment environment;

@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
    environment = event.getApplicationContext().getEnvironment();
    printProperties();
}

public void printProperties() {
    for (EnumerablePropertySource propertySource : findPropertiesPropertySources()) {
        log.info("********** " + propertySource.getName() + " **********");
        String[] propertyNames = propertySource.getPropertyNames();
        Arrays.sort(propertyNames);
        for (String propertyName : propertyNames ){
            String resolvedProperty = environment.getProperty(propertyName);
            String sourceProperty = propertySource.getProperty(propertyName).toString();
            if(resolvedProperty.equals(sourceProperty)) {
                log.info("{}={}", propertyName, resolvedProperty);
            }else {
                log.info("{}={} OVERRIDEN to {}", propertyName, sourceProperty, resolvedProperty);
            }
        }
    }
}

private List<EnumerablePropertySource> findPropertiesPropertySources() {
    List<EnumerablePropertySource> propertiesPropertySources = new LinkedList<>();
    for (PropertySource<?> propertySource : environment.getPropertySources()) {
        if (propertySource instanceof EnumerablePropertySource) {
            propertiesPropertySources.add((EnumerablePropertySource) propertySource);
        }
    }
    return propertiesPropertySources;
}

}

有人知道我怎么找到这些信息的来源吗?也就是说,如果有一个包含这些信息的文件,我如何找到该文件并进行更改?

谢谢

0 个答案:

没有答案