2017-09-13 128 views
3

我現在有3個屬性文件:
application.properties春天引導屬性文件外化

[email protected]@ 

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(值= 「類路徑:application.properties」)

當我用開發或生產配置文件進行編譯時,一切正常,但現在我想將屬性文件外化到我的Tomcat服務器的/ conf/localhost目錄,有關如何執行此操作的任何想法?

+0

只需將應用程序 - *。properties文件放置在部署了.jar的位置。 –

回答

0

您可以通過新的配置文件

java -jar myproject.jar --spring.config.location=classpath:/new.properties,file:/home/override.properties 

在罐內的配置文件中定義,這將覆蓋配置。