当前位置: 首页 > 知识库问答 >
问题:

Spring Boot参数化配置

张鹏鹍
2023-03-14
year2020.datasource.jdbcUrl=jdbc:postgresql://${built.url.2020}:5432/db_name
year2020.datasource.username=some_username
year2020.datasource.password=some_password
year2020.datasource.driverClassName=org.postgresql.Driver
year2020.datasource.validationQuery=SELECT 1

# And multiple similar configs for other resources and previous years
@Configuration
public class CopyPastedDataSource {

    @Bean(name = "year2020_datasource")
    @ConfigurationProperties(prefix = "year2020.datasource")
    public DataSource dataSource2020() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "year2019_datasource")
    @ConfigurationProperties(prefix = "year2019.datasource")
    public DataSource dataSource2020() {
        return DataSourceBuilder.create().build();
    }

    // And more beans for previous years
}

共有1个答案

商畅
2023-03-14

所以我找到的正是这个方法:

https://stackoverflow.com/A/26276872/7660079

https://stackoverflow.com/A/53554102/7660079

api.url.2020=api-2020.endpoint.com
api.url.2019=api-2019.endpoint.com
api.url.2018=api-2018.endpoint.com

@Configuration
@EnableConfigurationProperties

public class ApiConfiguration {
    @Bean
    @ConfigurationProperties(prefix = "api.url")
    public Map<Integer, String> getConfiguration() {
        return new HashMap<>();
    }
}
@Component
class APIConsumer {
    @Autowired
    Map<Integer, String> apiUrlsByYear;
}
 类似资料:
  • 在springboot应用程序中,我有一个jar,然后是一个子目录config with application。属性,applicationContext。xml和log4j。。。属性文件。 我正在尝试外部化log4j配置。application.properties是这样外部化的。 但是,当springboot运行时,它使用jar文件中的log4j配置文件。通过使用-Dlog4j.debug选

  • 类名 \Yurun\PaySDK\AlipayApp\Params\PublicParams 属性 名称 类型 说明 $format string 仅支持JSON $charset string 请求使用的编码格式,如utf-8,gbk,gb2312等 $sign_type string 商户生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,推荐使用RSA2。 RSA2需要PHP版本>

  • 类名 \Yurun\PaySDK\Weixin\Params\PublicParams 属性 名称 类型 说明 $sub_appid string 微信分配的子商户公众账号ID,服务商、银行服务商需要。 $mch_id string 微信支付分配的商户号 $sub_mch_id string 微信支付分配的子商户号,开发者模式下必填,服务商、银行服务商需要。 $sign_type string 签

  • 类名 \Yurun\PaySDK\Alipay\Params\PublicParams 属性 名称 类型 说明 $_input_charset string 商户网站使用的编码格式,如UTF-8、GBK、GB2312等。 $sign_type string DSA、RSA、MD5三个值可选,必须大写。 $appPrivateKey string 应用私有证书文件内容 $appPrivateKeyF

  • 本文向大家介绍MySQL 5.5.x my.cnf参数配置优化详解,包括了MySQL 5.5.x my.cnf参数配置优化详解的使用技巧和注意事项,需要的朋友参考一下 一直有耳闻MySQL5.5的性能非常NB,所以近期打算测试一下,方便的时候就把bbs.kaoyan.com升级到这个版本的数据库。今天正好看到一篇有关my.cnf优化的总结,虽然还没经过我自己的实践检验,但从文章内容来说已经写的很详