【发布时间】:2018-04-06 08:07:28
【问题描述】:
我有一个 Spring Boot 项目。
可以成功启动。
我添加了一个这样的测试:
@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.springframework.context.annotation.AnnotationConfigApplicationContext@758d0555: startup date [Wed Oct 25 17:00:09 CST 2017]; parent: org.springframework.web.context.support.GenericWebApplicationContext@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)
...
【问题讨论】:
标签: java spring-boot junit spring-cloud