外部属性Spring boot

时间:2017-09-16 13:40:51

标签: java spring-boot properties spring-boot-configuration

我试图让我的春季启动项目使用项目之外定义的属性。我已经尝试了文档中描述的步骤,但我无法让它工作。

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

.
+- folder
   +- properties
      +- application.properties
   +- myproject
      +- src

我将其用于VM选项:-Dspring.config.location=file:../properties/但它无效。我为spring.config.location尝试了多个值但没有成功(我想这个问题来自这里)。

1 个答案:

答案 0 :(得分:0)

我们说我是一个连接到Postgresql数据库的应用程序。我的项目之外的数据库连接详细信息位于某个集中版本控制系统中。我在我的应用中使用bootstrap.properties文件。我已在bootstrap.properties中配置以在应用启动时获取我的数据库连接详细信息。 例如,

postgresql.database.url:${databaseUrl}
postgresql.database.username:${databaseUsername}
postgresql.database.password:${databasePassword}

我将配置密钥作为bootstrap.properties中的值传递。在应用程序运行时,它将根据键获取相应的值。

相关问题