기본 application.properties 사용하지 않으려면 속성 파일을 JAR 패키지 외부에 넣으려면 다음 두 가지 방법을 사용할 수 있습니다.
전체 경로 만 설정할 수 있습니다. Java -jar JAR 패키지를 실행할 때 ClassPath를 지정할 수 없기 때문에 (매개 변수 또는 환경 변수를 통해 세트 클래스 경로를 덮어 쓸 수 있음).
방법 1 : 명령 줄 매개 변수를 전달하여 spring.config.location을 지정합니다.
java -jar -dspring.config.location = d : /ztest/config/config1.properties springbootrestdemo -0.0.1-snapshot.jar
spring.config.location 사용하여 경로를 지정 하여이 경로에서 application-{profile}.properties 찾을 수 있습니다.
spring.config.location 으로 경로를 지정한 다음 spring.config.name 으로 구성 파일 이름을 지정할 수도 있습니다.
쉼표로 여러 경로와 이름을 분리 할 수 있습니다
방법 2 : @PropertySource 주석을 사용하십시오.
@springbootApplication@propertySource (value = { "파일 : d : /ztest/config/config1.properties"}) public class public class springbootrestdemoapplication {public static void main (string [] args) {springApplication.run (springbootrestdemoapplication.class, class, class, class); }}Spring Boot 구성 파일과 JAR 외부의 로그 파일을 살펴 보겠습니다.
1. 패키지 JAR을 설정할 때 파일 제외
<Resource> <Resource> <cerce> <criptory> src/main/resources </directory> <excludes> <exclude>*. 속성 </excerties </exclude> <exclude> logback.xml </exclude> </excludes> </resource> </resources>
2. 시작시 위치를 지정하려면 매개 변수를 전달합니다.
java -jar xxx.jar ---spring.config.location = d :/springconfig/ -logging.config = d : /springconfig/logback.xml
구성 파일을 찾는 SpringBoot의 기본 위치는 다음과 같습니다.
// 순서는 최소에서 가장 구체적으로 (마지막으로 승리) 비공개 정적 최종 문자열 default_search_locations = "classPath :/, classPath :
요약
위는 편집기가 소개 한 스프링 부츠입니다. 구성 파일과 로그 파일을 JAR 외부에 넣습니다. 모든 사람에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨 주시면 편집자가 제 시간에 모든 사람에게 답장을 드리겠습니다. Wulin.com 웹 사이트를 지원해 주셔서 대단히 감사합니다!