且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Spring Boot中使用环境变量动态设置tableName?

更新时间:2023-09-09 20:58:16

可以通过更改的DynamoDBMapperConfig bean更改表名称.

The table names can be altered via an altered DynamoDBMapperConfig bean.

对于必须为每个表加上文字前缀的情况,可以这样添加Bean.这里的前缀可以是您所用环境的名称.

For your case where you have to Prefix each table with a literal, you can add the bean as such. Here the prefix can be the environment name in your case.

 @Bean
public TableNameOverride tableNameOverrider() {
    String prefix = ... // Use @Value to inject values via Spring or use any logic to define the table prefix
    return TableNameOverride.withTableNamePrefix(prefix);
}

有关更多详细信息,请在此处查看完整的详细信息: https://github.com/derjust/spring-data-dynamodb/wiki/运行时更改表名称

For more details check out the complete details here: https://github.com/derjust/spring-data-dynamodb/wiki/Alter-table-name-during-runtime