Maven을 통해 Spring Boot에서 활성 프로파일 구성
Maven 3을 사용하여 Spring Boot 어플리케이션에서 액티브한 프로파일을 설정하려고 합니다.
pom.xml에서 기본 활성 프로파일과 속성 spring.profiles.active를 development로 설정합니다.
<profiles>
<profile>
<id>development</id>
<properties>
<spring.profiles.active>development</spring.profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
그러나 응용 프로그램을 실행할 때마다 로그에 다음과 같은 메시지가 표시됩니다.
No active profile set, falling back to default profiles: default
Spring Boot (어플리케이션 개발.프로퍼티) application.properties (어플리케이션.properties.
Maven 프로파일을 사용하여 Spring Boot 액티브프로파일을 설정하려면 그 외에 무엇을 해야 합니까?
도와주셔서 대단히 감사합니다.
메이븐 프로파일과 스프링 프로파일은 완전히 다릅니다.은 pom.xml을 정의합니다.spring.profiles.active
이 변수는 빌드 프로세스에서 사용할 수 있지만 런타임에는 사용할 수 없습니다.그렇기 때문에 디폴트프로파일만 활성화 됩니다.
메이븐 프로파일을 스프링과 결합하려면 어떻게 해야 할까요?
빌드 변수를 응용 프로그램에 전달해야 시작 시 사용할 수 있습니다.
합니다.
application.properties
:spring.profiles.active=@spring.profiles.active@
@spring.profiles.active@
메이븐 씨pom.xml에서 리소스 필터링을 활성화합니다.
<build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> … </build>
되면, 「」의 모든 됩니다.
src/main/resources
과 Maven의 됩니다.application.properties
메이븐
자세한 내용은 이 사용 사례에 대해 설명한 게시물을 참조하십시오.
또는 비교적 쉽게:
mvn spring-boot:run -Dspring-boot.run.profiles={profile_name}
스프링 부트 애플리케이션의 프로파일을 설정하는 방법은 여러 가지가 있습니다.
속성 파일에 다음 항목을 추가할 수 있습니다.
spring.profiles.active=dev
프로그래밍 방식:
SpringApplication.setAdditionalProfiles("dev");
테스트를 통해 액티브한 프로파일을 쉽게 지정할 수 있습니다.
@ActiveProfiles("dev")
Unix 환경에서
export spring_profiles_active=dev
JVM 시스템 파라미터
-Dspring.profiles.active=dev
예: 프로파일을 사용하여 springboot jar 파일을 실행합니다.
java -jar -Dspring.profiles.active=dev application.jar
다음 명령을 사용하여 실행할 수 있습니다.에서는 스프링 .local
:
spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=local"
개발에서는 특정 Maven 프로파일이 활성화 되어 있을 때 스프링부트 프로파일을 활성화 하는 것은 스트레이트입니다.Maven 프로파일에서는 다음과 같은 spring-boot-maven-plugin 속성을 사용해야 합니다.
<project>
<...>
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<profiles>
<profile>development</profile>
</profiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profiles>
</...>
</project>
하여 Spring 을 모두 할 수 .development
: profile :
mvn spring-boot:run -Pdevelopment
Spring Boot 프로파일을 동일한 프로파일명으로 Maven 프로파일에 매핑할 수 있는 경우 단일 Maven 프로파일을 정의하고 Maven 속성이 검출되었을 때 이를 netable로 할 수 있습니다.은 '알다'를 할 때 해야 하는 입니다.mvn
명령어를 입력합니다.
프로파일은 다음과 같습니다.
<profile>
<id>spring-profile-active</id>
<activation>
<property>
<name>my.active.spring.profiles</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<profiles>
<profile>${my.active.spring.profiles}</profile>
</profiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
또한 다음 명령을 실행하여 Spring Boot와 Maven을 모두 사용할 수 있습니다.development
프로파일:
mvn spring-boot:run -Dmy.active.spring.profiles=development
또는 다음과 같습니다.
mvn spring-boot:run -Dmy.active.spring.profiles=integration
또는 다음과 같습니다.
mvn spring-boot:run -Dmy.active.spring.profiles=production
그래서...
이러한 종류의 설정은 일반적인 Maven 프로파일에서 사용하는 것과 같이 타당합니다.my.active.spring.profiles
일부 작업을 수행하거나 일부 가치를 부여하기 위해 전달되는 속성입니다.
예를 들어, 이 방법을 사용하여 응용 프로그램을 패키징하는 범용 Maven 프로파일을 설정하고 선택한 환경에 고유한 도커 이미지를 구축합니다.
Spring Boot Maven 플러그인을 사용해야 합니다.
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.1.RELEASE</version>
<configuration>
<profiles>
<profile>foo</profile>
<profile>bar</profile>
</profiles>
</configuration>
...
</plugin>
...
</plugins>
...
</build>
...
</project>
다른 환경에서 자동화 테스트를 실행하고 싶습니다.
따라서 명령어 maven 명령어에 다음 명령을 추가합니다.
spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=productionEnv1"
다음은 솔루션을 찾은 링크입니다.[ 1 ] https://github.com/spring-projects/spring-boot/issues/1095
Daniel Olszewski의 훌륭한 답변 https://stackoverflow.com/a/42391322/13134499을 테스트에만 사용하고 싶다면 명확히 하고 싶습니다.
테스트를 위해 Maven 프로파일을 Spring과 결합하는 방법은?
- 다음과 같이 변수를 정의합니다.
pom.xml
...
<properties>
<spring.profiles.active>development</spring.profiles.active>
</properties>
- 에서 플레이스 홀더를 정의합니다.
application-test.properties
…에.src/test/resources
:
spring.profiles.active=@spring.profiles.active@
- 사용자 내에서 리소스 필터링 사용
pom.xml
:
<build>
...
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
<testResources>
</build>
파일 구조:
/src/메인/메인/메인
=>
application.properties:
spring.profiles.active:@spring.profiles.active@'
application-dev.properties
application-module.properties
IDE-Eclipse:
Right click on the project=>Run As=>Run Configuration=>Arguments=>VM Arguments:-Dspring.profiles.active=dev
CMD:
mvn spring-boot:run -Dspring.profiles.active=dev
mvn clean install -Dspring.profiles.active=dev
언급URL : https://stackoverflow.com/questions/42390860/configure-active-profile-in-springboot-via-maven
'programing' 카테고리의 다른 글
저장 상태 변경 시 React-redux 구성 요소가 다시 렌더링되지 않음 (0) | 2023.02.26 |
---|---|
엔티티 클래스 이름이 밑줄이 있는 SQL 테이블 이름으로 변환됩니다. (0) | 2023.02.26 |
리액트 컴포넌트 'displayName'의 용도는 무엇입니까? (0) | 2023.02.26 |
조건에 따라 ui-sref 사용 안 함 (0) | 2023.02.26 |
리액트 네이티브에서 스타일의 기본 단위는 무엇입니까? (0) | 2023.02.26 |