-
Notifications
You must be signed in to change notification settings - Fork 315
Description
junit单元测试报错
Caused by: java.lang.IllegalStateException: org.springframework.web.context.support.GenericWebApplicationContext@3fb1549b has not been refreshed yet
at org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1141)
at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1293)
at com.alibaba.spring.util.BeanUtils.getBeanNames(BeanUtils.java:153)
at com.alibaba.spring.util.BeanUtils.getBeanNames(BeanUtils.java:136)
at com.alibaba.nacos.spring.util.NacosBeanUtils.isBeanDefinitionPresent(NacosBeanUtils.java:207)
at com.alibaba.nacos.spring.util.NacosBeanUtils.registerInfrastructureBeanIfAbsent(NacosBeanUtils.java:174)
at com.alibaba.nacos.spring.util.NacosBeanUtils.registerNacosApplicationContextHolder(NacosBeanUtils.java:285)
at com.alibaba.nacos.spring.util.NacosBeanUtils.registerNacosCommonBeans(NacosBeanUtils.java:372)
at com.alibaba.nacos.spring.context.annotation.NacosBeanDefinitionRegistrar.registerNacosAnnotationBeans(NacosBeanDefinitionRegistrar.java:83)
at com.alibaba.nacos.spring.context.config.xml.NacosAnnotationDrivenBeanDefinitionParser.parse(NacosAnnotationDrivenBeanDefinitionParser.java:49)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1391)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1371)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:179)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:149)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:96)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:511)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
... 37 more
Describe what you expected to happen
How to reproduce it (as minimally and precisely as possible)
1.spring.xml 中 import nacos配置
<import resource="nacos-config.xml"/>
nacos-config.xml配置如下
nacos:annotation-driven</nacos:annotation-driven>
<nacos:global-properties server-addr="x.x.x.x:8848"/>
<nacos:property-source data-id="projectName" group-id="DEFAULT_GROUP" auto-refreshed="true"/>
3. 启动单元测试 https://github.com/RunWith(SpringRunner.class) @SpringJUnitWebConfig @ContextConfiguration(locations = {"classpath:spring.xml" }) @activeprofiles("dev") public class XTest{ @Autowired private XService xService;
@test
public void testCreate(){
xService.doBusiness();
}
}
随便自动注入个服务,然后test方法中调用自动注入服务方法即可
Tell us your environment
spring版本5.3.6
nacos-spring-context版本1.1.0