如何替换 application.properties 条目并将它们公开为代码或 bean

问题描述 投票:0回答:0

在我们的团队中,我们同意将所有配置用作代码(比如 AppConfiguration 类)即:

@Value("${spring.datasource.url:jdbc:postgresql://localhost:5432/postgres}");
private String jdbcUrl;

然后使用它们来配置具有此值的bean:

@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource.configuration")
public DataSource teamDataSource() {
        return dataSourceProperties().initializeDataSourceBuilder().build();
}

@Bean
@Primary
public DataSourceProperties telemetryControlServiceDataSourceProperties() {
    DataSourceProperties dataSourceProperties = new DataSourceProperties();
    dataSourceProperties.setUrl(appConfig.getJdbcUrl());
....
    return dataSourceProperties;
}

我的问题: 随着配置属性的增加,我不能根据我们的协议在 application.properties 文件中放置任何内容,而且我必须搜索 @ConfigurationProperties 的 pojos,有时我找不到。是否有一种通用/通用的方法来公开 applications.properties 中的各种配置属性? 即我能够找到一些执行器属性,但其中大部分我不能:

management.endpoints.web.base-path=/debug
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=env,beans
management.endpoint.health.show-details=always
management.endpoint.metrics.enabled=true
management.endpoint.prometheus.enabled=true
management.endpoint.loggers.enabled=true
java spring spring-boot configuration-files
© www.soinside.com 2019 - 2024. All rights reserved.