Springboot fat jar应用连接数据库时PROD数据库密码的标准是什么

What is the standard for PROD database password in the Springboot fat jar application connecting a database

我有一个连接到数据库的 springboot 应用程序,目前数据库密码在应用程序属性中以纯文本形式显示。

PROD环境下安全保护密码的标准是什么?

如果应用程序密码位于作为 JAR 的一部分内置的应用程序属性中,尤其是当应用程序处于活动状态时,如何更改数据库密码?

您可以使用 jasypt to handle the encryption and then use Jasypt's Spring integration or this Jasypt Spring Boot Starter 将其连接到 Spring。

这将允许您定义一个加密的数据库密码 属性,例如 application.properties 例如

db.password=ENC(.....)

你问题的另一部分是:

How to change the database password if the application password is inside the application properties

您可以通过使用系统属性覆盖属性文件中定义的属性来实现。例如:-Ddb.password='....'。您还可以定义一个额外的属性源,它在您的 JAR 外部并且可以在运行时进行编辑。例如:

@PropertySources({
        @PropertySource(value = "classpath:/**.properties"),
        @PropertySource(value = "file:/some/external/directory/override.properties", ignoreResourceNotFound = true)
})
public class Application {
    // ...
}  

创建文件 /some/external/directory/override.properties 并用 db.password=... 填充它会导致您的应用程序 - 在下次重新启动时 - 使用 that 属性 值.