【发布时间】:2012-03-09 14:58:02
【问题描述】:
运行我的测试类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:eq-mo-dcc-context-block.xml"})
public class SpringTest {
@Autowired
private DateUtils dateManager;
@Autowired
private RegionFilter filter;
@Autowired
private ApplicationContext appContext;
@Test
public void test_This()
{
Object obj = appContext.getBean("BlockTransformer");
BlockTransformer Trans = (BlockTransformer) obj;
}
所有非常早期的阶段,但是配置文件出现的问题是从其他 Maven 模块/项目访问 bean。但是我在 src/test/resources 下拥有所有 xml,因此它可以获取 xml。然而,当我试图拿起我得到的类文件时:
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [dcc.mdp.DefaultMessageListener] for bean with name 'BlockMessageListener' defined in class path resource [eq-mo-dcc-context-block.xml]; nested exception is java.lang.ClassNotFoundException: dcc.mdp.DefaultMessageListener
此类驻留在同级 maven 模块中,但无法从测试类中获取。如何让类知道来自其他模块而不是它自己的类?
【问题讨论】:
标签: java spring testing maven junit