2017-09-13 12 views
3

ファイル:
application.properties春ブートプロパティは、私は現在、3つのプロパティファイル持って外在

[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 

私は私のの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の中で次のように私のMavenのプロファイルが設定されている:annotaion @PropertySource(値は= "クラスパス:application.properties")

開発やプロダクションプロファイルでコンパイルするとすべてうまく動作しますが、プロパティファイルをTomcatサーバーの/ conf/localhostディレクトリに外部化したいと思います。

+0

.jarが配置されている場所にapplication - *。propertiesファイルを置くだけです。 –

答えて

0

あなたは、新しいコンフィギュレーションファイル

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

jarファイル内の構成ファイルに定義されたこのオーバーライドされます設定を渡すことができます。

関連する問題