当在子类中声明bean时,SpringXML初始化bean,但如果在父类中声明bean,则bean初始化失败

当在子类中声明bean时,SpringXML初始化bean,但如果在父类中声明bean,则bean初始化失败,spring,unitils,Spring,Unitils,在我的应用程序中有很多基于Unitils的集成测试类,它们使用@SpringApplicationContext(使用来自不同模块的不同SpringXML)。为了减少正在创建的spring上下文的数量,我们计划创建一个基本测试类,并仅从该基类初始化spring上下文,并进行所有其他测试以扩展该基类 基类: com.org.module1.mypack @SpringApplicationContext({“spring-module1.xml”、“spring-module2.xml”、“spr

在我的应用程序中有很多基于Unitils的集成测试类,它们使用
@SpringApplicationContext
(使用来自不同模块的不同SpringXML)。为了减少正在创建的spring上下文的数量,我们计划创建一个基本测试类,并仅从该基类初始化spring上下文,并进行所有其他测试以扩展该基类

基类:

com.org.module1.mypack

@SpringApplicationContext({“spring-module1.xml”、“spring-module2.xml”、“spring-module3.xml”}) 公共抽象类基类测试{ ... }

更改前的子类:

com.org.module1.mypack.performance

@SpringApplicationContext({“spring-module4.xml”}) 公共类ChildTest扩展了BaseTest{ .. }

更改后的基类:

com.org.module1.mypack

@SpringApplicationContext({“spring-module1.xml”、“spring-module2.xml”、“spring-module3.xml”、“spring-module4.xml”}) 公共抽象类基类测试{ ... }

更改后的子类:

com.org.module1.mypack.performance

//@SpringApplicationContext({“spring-module4.xml”}) 公共类ChildTest扩展了BaseTest{ .. }

现在,我收到以下错误消息,但未创建我的上下文:
org.springframework.beans.factory.NoSuchBean定义异常:找不到依赖项类型为[com.org.module5.prepare.MyBean]的匹配bean:至少需要1个符合此依赖项autowire候选项条件的bean。依赖项注释:{@org.springframework.beans.factory.annotation.Autowired(required=true),@org.springframework.beans.factory.annotation.Qualifier(value=myBean)}

当spring-module4.xml位于子类中时,正常创建上下文,所有测试都照常执行


注意:所有spring xml文件都在src/main/resources中,除了spring-module4.xml在src/test/resources中

默认情况下,类上的注释不会被继承,除非它们的定义中有@inherited。

这意味着您也必须将@SpringApplicationContext放在子级上。但是按照文档:,您可以保留现有的新配置。我尝试将
@SpringApplicationContext
添加到子类中。。。但是仍然会得到相同的错误
NoSuchBeanDefinitionException
清楚地表明父类对MyBean没有可见性。这对任何人都有意义吗?