0
統合テストを実行しようとしたとき、私は次の例外があります。恐ろしい「EmbeddedWebApplicationContextを開始できません」というエラー
org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
私は多くのフォーラムのエントリを読んではなく任意の解決策を見つけていません。
統合テスト
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = WebInitializer.class)
@DataJpaTest
@Sql("/db/data.sql")
public class ReportEventIntTest {
@Autowired
private TestRestTemplate restTemplate;
@Test
public void reportEvent() {
Map<String, String> eventMap = new HashMap<>();
this.restTemplate.postForEntity("/worker/event", eventMap, String.class);
}
}
春ブート設定
@Configuration
@ComponentScan(basePackages = {"org.reaction.engine.collector.controller",
"org.reaction.engine.persistence.service",
"org.reaction.engine.persistence.converter",
"org.reaction.engine.service"})
@EnableAutoConfiguration
@ImportResource("classpath:applicationContext.xml")
@Profile("threadPool") // define the default profile: it can be overridden by -Dspring.profiles.active=...
public class WebInitializer extends SpringBootServletInitializer implements WebApplicationInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WebInitializer.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(WebInitializer.class, args);
}
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
return factory;
}
}
のGradleは
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.4.3.RELEASE'
}
}
dependencies {
compile project(':common')
compile 'org.springframework:spring-context-support'
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-integration'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.apache.httpcomponents:httpclient:4.5.2'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
providedCompile 'javax.enterprise.concurrent:javax.enterprise.concurrent-api:1.0'
runtime 'mysql:mysql-connector-java'
// ---------------------- TESTING ----------------------
testCompile 'com.jayway.restassured:rest-assured:2.9.0'
testCompile 'org.springframework.boot:spring-boot-starter-test'
//testRuntime 'org.hsqldb:hsqldb'
testRuntime 'com.h2database:h2'
testRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}
任意のアイデアを提出:次のように私のファイルとは?
私はどんな考えにも大いに感謝します!
よろしく、 V.
テストを実行するのにIntelliJ IDEAを使用していますか? –
こんにちはAndy、いいえ一方、私は答えを見つけました。問題はプロファイルにあります。テストクラスで設定する必要があります... – Viktor