Java Spring引导属性文件外部化
我目前有3个属性文件:Java Spring引导属性文件外部化,java,maven,tomcat,spring-boot,maven-profiles,Java,Maven,Tomcat,Spring Boot,Maven Profiles,我目前有3个属性文件: 应用程序属性 spring.profiles.active=@activatedProperties@ #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.
应用程序属性
spring.profiles.active=@activatedProperties@
#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
#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
应用程序开发.属性
spring.profiles.active=@activatedProperties@
#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
#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
应用程序生产.属性
spring.profiles.active=@activatedProperties@
#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
#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
我在我的pom.xml中设置了如下maven配置文件
<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>
发展
发展
真的
生产
生产
和我的数据源配置:annotation@PropertySource(value=“classpath:application.properties”)
当我使用开发或生产概要文件进行编译时,一切都很好,但现在我想将属性文件外部化到Tomcat服务器的/conf/localhost目录中,知道如何做到这一点吗?使用Spring Cloud Config server为您提供一个集中的外部化配置(除此之外还有很多)
您可以传递新的配置文件
java -jar myproject.jar --spring.config.location=classpath:/new.properties,file:/home/override.properties
这将覆盖jar中配置文件中定义的配置。只需将应用程序-*.properties文件放在部署.jar的位置即可。