2017-09-13 2 views
3

파일 :
application.properties봄 부팅 속성 내가 현재 3 개 곳의 파일이 외부화

[email protected]@ 

#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 application-develoment.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의 : 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 

항아리 내부 구성 파일에 정의 된이 우선합니다 구성을 전달할 수 있습니다.