[英]Spring Boot properties file externalization
我目前有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:annotaion @PropertySource(value =“classpath:application.properties”)
當我使用開發或生產配置文件進行編譯時,一切正常,但現在我想將屬性文件外部化到我的Tomcat服務器的/ conf / localhost目錄,有關如何做到的任何想法?
使用Spring Cloud Config服務器為您提供集中的外部化配置(以及更多)。
您可以傳遞新的配置文件
java -jar myproject.jar --spring.config.location=classpath:/new.properties,file:/home/override.properties
這將覆蓋jar中配置文件中定義的配置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.