我敢肯定我错过了一些简单的东西。 bar在junit测试中被自动装入,但为什么不在foo里面自动装入?Autowire不在junit测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"beans.xml"})
public class BarTest {
@Autowired
Object bar;
@Test
public void testBar() throws Exception {
//this works
assertEquals("expected", bar.someMethod());
//this doesn't work, because the bar object inside foo isn't autowired?
Foo foo = new Foo();
assertEquals("expected", foo.someMethodThatUsesBar());
}
}
你是什么意思,“bar inside foo”? – skaffman 2011-01-14 17:54:06