我是春天和Maven的新手.最近我构建了spring MVC项目并使用maven来管理项目结构和依赖项.
当我编写单元测试时,我遇到了一个问题,即我无法从“src / main / java”获取bean,而且似乎上下文只加载来自“src / test / java”的bean.
这是我的代码.
单元测试:src / test / java / com / web / component / form
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:META-INF/spring/applicationContext-web-test.xml"})
public class FormTest {
@Autowired
private BeanFactory beanFactory; // I override this bean by myself
}
配置XML文件:src / test / resources / META-INF / spring / applicationContext-web-test.xml
这里的以下组件扫描似乎只扫描src / test / java中定义的bean,而不是src / main / java.
覆盖BeanFactory类位于src / main / java / com / web / helper /中.
错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.web.helper.BeanFactory] f