我目前有 3 个属性文件:
application.properties
spring.profiles.active=@activatedProperties@
application-develoment.properties
#DB properties:
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://localhost:5432/mydb
db.username=user
db.password=pswd
#Data source management:
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=true
hibernate.current_session_context_class=thread
application-production.properties
#DB properties:
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://localhost:5432/myproddb
db.username=admin
db.password=admin
#Data source management:
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=false
hibernate.current_session_context_class=thread
我的 Maven 配置文件在我的 pom.xml
中设置如下<profiles>
<profile>
<id>development</id>
<properties>
<activatedProperties>development</activatedProperties>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>production</id>
<properties>
<activatedProperties>production</activatedProperties>
</properties>
</profile>
</profiles>
和我的 DataSourceConfig 的:注释 @PropertySource(value = "classpath:application.properties")
当我使用开发或生产配置文件编译时一切正常,但现在我想将属性文件外部化到我的 Tomcat 服务器的/conf/localhost 目录,知道如何做到这一点吗?
最佳答案
使用 Spring Cloud Config 服务器为您提供集中的、外部化的配置(以及更多)。
关于java - Spring Boot 属性文件外部化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46192404/