spring boot 프로필 시작 을 어떻게 지정 합 니까?
4969 단어 springbootprofile시동 을 걸다
다음 그림 에서 보 듯 이:
pom.xml 설정 은 다음 과 같 습 니 다.
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
<scope>runtime</scope>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
</dependencies>
<!-- profile-->
<profiles>
<profile>
<id>dev</id>
<properties>
<!-- ${environment} -->
<environment>dev</environment>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<environment>test</environment>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<environment>prod</environment>
</properties>
</profile>
</profiles>
<build>
<finalName>spring-boot-lean-${environment}</finalName>
<resources>
<!-- -->
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>application-*.yml</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<!-- -->
<includes>
<include>application-${environment}.yml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
로 컬 개발 사용 개발 환경,아이디어 시작 개발 환경 설정 은 다음 과 같 습 니 다.1.설정 편집 을 클릭 합 니 다
2.아래 그림 과 같이 설정
3.프로젝트 시작
콘 솔 은 application-dev.yml 에서 설정 한 변 수 를 인쇄 했 습 니 다.
개발 할 때 하나의 프로젝트 가 여러 개의 인 스 턴 스 를 시작 해 야 하 는 장면 도 있 습 니 다.아 이 디 어 는 하나의 spring boot 프로젝트 가 여러 개의 인 스 턴 스 를 시작 하 는 것 을 지원 합 니 다.
방법 은 매우 간단 합 니 다.위의 튜 토리 얼 에 따라 아이디어 에 시작 설정 을 새로 만 들 고 Active profiles 를 prod 로 지정 하면 됩 니 다.다음 그림:
다음 그림 을 통 해 로 컬 에서 여러 개의 spring boot 인 스 턴 스 를 시작 할 수 있 습 니 다.
다 중 환경 패키지
1.maven 포장 명령 실행:
포장 테스트:
mvn clean package -D maven.test.skip=true -P test
이렇게 전 화 된 가방 에는 yml 파일 만 포 함 됩 니 다:application.yml,application-test.yml패키지 prod:
mvn clean package -D maven.test.skip=true -P test
이렇게 걸 려 있 는 가방 에는 yml 파일 만 포 함 됩 니 다:application.yml,application-prod.yml2、jar 패키지 실행 찾기
java-jar 이름.jar--spring.profiles.active=prod
테스트 환경의 가방 이 나 오 면 실행:
java-jar 이름.jar--spring.profiles.active=test
보충 점
mvn clean package-D maven.test.skip=true-P test 를 실행 합 니 다.target 디 렉 터 리 에는 application.yml,application-test.yml 만 있 습 니 다.이때 idea 를 사용 하여 프로젝트 를 시작 할 때 dev 설정 을 사용 할 수 없습니다.target 에 application-dev.yml 이 없 기 때 문 입 니 다.
target 을 삭제 한 후 프로젝트 를 다시 시작 해 야 합 니 다.이때 target 에 모든 프로필 이 있 고 dev 설정 을 사용 할 수 있 습 니 다.
이상 은 개인 적 인 경험 이 므 로 여러분 에 게 참고 가 되 기 를 바 랍 니 다.여러분 들 도 저 희 를 많이 응원 해 주시 기 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin Springboot -- 파트 14 사용 사례 REST로 전환하여 POST로 JSON으로 전환前回 前回 前回 記事 の は は で で で で で で を 使っ 使っ 使っ て て て て て リクエスト を を 受け取り 、 reqeustbody で 、 その リクエスト の ボディ ボディ を を 受け取り 、 関数 内部 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.