2017-10-25 11 views
1

私はSpringブートプロジェクトを取得しました。
正常に起動できます。
私はこのようなテストを追加しました: "!成功"Springブートプロジェクトのjunitテスト後のBeanCreationNotAllowedException

@WebAppConfiguration 
@RunWith(SpringJUnit4ClassRunner.class) 
@SpringBootTest(classes = SopStart.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK) 
public class Test{ 
    @Test 
    public void test(){ 
     System.out.println("success!"); 
    } 
} 

正常に印刷できます。しかし、最後に、私は、例外が発生しました:

2017-10-25 17:00:42.481 INFO [bootstrap,,,] 7280 --- [  Thread-15] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]758d0555: startup date [Wed Oct 25 17:00:09 CST 2017]; parent: org.s[email protected]75d4a80f 
2017-10-25 17:00:42.492 WARN [bootstrap,,,] 7280 --- [  Thread-15] s.c.a.AnnotationConfigApplicationContext : Exception thrown from ApplicationListener handling ContextClosedEvent 

org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:216) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    ... 

答えて

0

それはデフォルトApplicationクラスを拾っています。 EurekaClientAutoConfigurationを含む特定の自動構成された豆を除外したテストクラスに対して、あなたのテストが不満を示している主な理由である、あなたの勝ちの構成を定義してみてください。

おそらく、@WebAppConfigurationも必要ありません。あなたはjava.lang.IllegalStateExceptionを得るかもしれません。ここで

は、

@ActiveProfiles("test") 
//@WebAppConfiguration 
@RunWith(SpringJUnit4ClassRunner.class) 
@SpringBootTest(classes = TestExample.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 
@ContextConfiguration(classes = {Test.CustomConfiguration.class}) 
public class Test { 

    @Configuration 
    @EnableConfigurationProperties 
    @EnableAutoConfiguration(exclude = {HibernateJpaAutoConfiguration.class, 
      JpaRepositoriesAutoConfiguration.class, 
      DataSourceAutoConfiguration.class, 
      EurekaClientAutoConfiguration.class}) 
    static class CustomConfiguration { 

    } 

    @Test 
    public void test() { 
     System.out.println("success!"); 
    } 
} 
例です
関連する問題