【发布时间】:2011-01-14 17:52:21
【问题描述】:
我确定我错过了一些简单的东西。 bar 在 junit 测试中自动装配,但为什么 bar 里面的 foo 不自动装配?
@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());
}
}
【问题讨论】:
-
你是什么意思,“酒吧里面 foo”?