@Profile 기능을 사용하여 프로덕션/dev 환경 구성과 '테스트'구성을 분리하려고합니다. 내 구성 클래스에 @profile를 추가 할 때 내가 얻을 :@Profile 원인 EmbeddedWebApplicationContext를 시작할 수 없습니다
Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:124)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at mypackage.configuration.PhoenixConfiguration.main(PhoenixConfiguration.java:26)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:174)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:147)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:121)
... 7 more
구성 클래스는 다음과 같습니다
@Configuration
@EnableAutoConfiguration
@ComponentScan("mypackage")
@EnableJpaRepositories(basePackages = "mypackage.repository")
@EntityScan(basePackages = "mypackage.phoenix.domain")
@PropertySource("classpath:properties/application-production.properties")
@EnableWebMvc
@Profile("production")
public class PhoenixConfiguration extends WebMvcConfigurerAdapter{
public static void main(String[] args) throws Exception {
SpringApplication.run(PhoenixConfiguration.class, args);
}
}
필자 application-production.properties 생산에 활성화 된 프로파일을 설정하려고
spring.profiles.active=production (with and without ")
또는 cmd를 명령 mvn spring-boot:run -Dspring.profiles.active=production
아무것도 할 수 없습니다. 물론 @Profile을 제거하면 모든 것이 작동하지만 테스트에서는 프로덕션 데이터베이스를 사용하고 있습니다.)
답을위한 thx! 봄철 부츠가하는 일의 양은 '정상적인'봄 사용자에게는 약간 놀랍습니다.) 어쨌든 @EnableJpaRepositories를 사용해야했습니다. – freakman
'PhoenixApplication'이 jpa 저장소 인터페이스가있는 패키지를 다루지 않는 한, 그렇게하지 않아도됩니다. 일반적으로 응용 프로그램 클래스를 상위 패키지에 넣습니다. (당신의 경우에는'mypackage') 그래서 모든 것을 가져올 빈'@ ComponentScan'을 사용할 수 있습니다. 이것은 또한 기본으로 구성된 EnableJpaRepositories에 의해 사용되는 기본입니다. –
아아 네, PhoenixApplication 클래스는 mypackage.configuration에 있으며 저장소는 mypackage.repository에 있습니다. – freakman