Ich bin sicher, ich vermisse etwas Einfaches. Bar wird im Junit-Test autowired, aber warum wird nicht innerhalb von foo autowired?Autowire funktioniert nicht in Junit Test
@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());
}
}
Was meinst du, "bar inside foo"? – skaffman