Tôi chắc chắn rằng tôi thiếu một cái gì đó đơn giản. thanh được autowired trong thử nghiệm junit, nhưng tại sao không thanh bên trong foo nhận autowired?Autowire không hoạt động trong thử nghiệm 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());
}
}
Ý của bạn là "bar inside foo"? – skaffman