2016-12-20 2 views
1

で行方不明EmbeddedServletContainerFactoryこんにちは私は、アプリケーションは私がfolllowing依存関係@SpringBootTest

を持っているのpom.xmlにこの

@SpringBootApplication 
@EnableJpaAuditing 
@ComponentScan("de.myfirm.myservice.service") 
public class MyApplication{ 
.... 
} 

のように見えるこの

@RunWith(SpringRunner.class) 
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,classes={MyApplication.class}) 
@DataJpaTest 
public class MyTest { 

    @Autowired 
    private TestRestTemplate restTemplate; 

    @Autowired 
    private MyService myService; 
    .... 

    @Test 
    public void myTest(){ 
    .... 
    } 
} 

のように見えるのテストを、書かれています

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jersey</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-starter-tomcat</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-starter-logging</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jetty</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-log4j2</artifactId> 
    </dependency> 

このアプリケーションは、Jerseyを使用するWebサービスです。アプリケーションが起動されると、組み込みサーブレットコンテナが期待通りに起動されます。テストでは私はあなたがのpom.xmlでspring-boot-starter-tomcatを除いている例外

java.lang.IllegalStateException: Failed to load ApplicationContext 
.... 
Caused by: 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. 
.... 
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean. 

答えて

1

を取得します。 埋め込み型のTomcatでスプリングブートテストを実行するには、この依存関係が必要です。

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat --> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-tomcat</artifactId> 
    <version>1.4.2.RELEASE</version> 
    <scope>test</scope> 
</dependency> 
関連する問題