spring boot, maven 사용자 정의 프로필

2561 단어 maven
pom. xml 에 탭 을 설정 하여 프로필 로 딩 경 로 를 지정 합 니 다.

        
            local
            
                
                    
                        src/main/profile
                    
                    
                        src/main/resources
                    
                
            
            
                true
            
        
    

resources 속성 은 파일 자원 을 설정 하 는 경 로 를 지정 합 니 다.
id 는 maven 을 컴 파일 할 때 대응 하 는 값 을 지정 하고 해당 하 는 id 를 사용 할 수 있 는 profile 입 니 다.
activationByDefault 속성 은 이 프로필 을 기본 불 러 오기 프로필 로 지정 합 니 다.
컴 파일 할 때 mvn - P local 명령 을 사용 하면 id 를 local profile 로 불 러 옵 니 다.
 
프로필 을 설정 한 후 프로그램 을 실행 하면 target / classes 디 렉 터 리 에 application. properties 파일 이 있 습 니 다. 열 어 보 세 요. 자신의 프로필 을 위 한 것 입 니 다.
그럼 프로필 에 두 개의 경로 가 설정 되 어 있 지 않 습 니까?src / main / profile 과 src / main / resources, 왜 application. properties 만 있 습 니까?src / main / resources 의 프로필 에 설정 이 쓰 여 있 지 않 습 니 다. 그런데 이 프로필 은 왜 classpath 에 불 러 오지 않 았 습 니까?
pom. xml 의 prolees 설정 을 다음 과 같이 조정 해 보 세 요.

        
            local
            
                
                    
                        src/main/resources
                    
                    
                        src/main/profile
                    
                
            
            
                true
            
        
    

다시 실행 하 니 프로그램 이 잘못 되 었 습 니 다. 설정 을 찾 을 수 없습니다. target / classes 에 들 어가 보 니 application. properties 에는 아무것도 없습니다.
다시 말 하면 pom. xml 에서 profflee 의 경 로 는 아래 에서 위로 불 러 옵 니 다. 그러면 같은 이름 의 파일 이 있 으 면 위의 profflee 경 로 는 아래 를 덮어 씁 니 다.
두 경로 의 프로필 을 다른 이름 으로 바 꾸 면 target / classes 에 두 속성 프로필 이 있 습 니 다.
그러나 이 때 는 spring boot 메 인 클래스 에 새 속성 파일 의 주 해 를 추가 해 야 합 니 다.
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@PropertySource("classpath:app.properties")
public class SpringbootApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootApplication.class, args);
    }
    
}

큰 성 과 를 거두다.

좋은 웹페이지 즐겨찾기