我敢肯定我錯過了一些簡單的東西。 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