2017-09-16 102 views
0

我试图让我的弹簧引导项目使用在项目外定义的属性。我已经尝试了文档中描述的步骤,但我无法使其工作。外部属性弹簧启动

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没有成功(我想这个问题是从这里)。

+0

#1。尝试使用虚拟机选项上的全限定路径,例如:'-Dspring.config.location = file:/ app/config/properties /'。 #2。尝试使用'--'选项而不是VM选项,例如:'java -jar myproject.jar --spring.config.location = file:../ properties /' – Rafa

回答

0

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

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

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