Autowire not working in junit test

Posted by Dave Paroulek on Stack Overflow See other posts from Stack Overflow or by Dave Paroulek
Published on 2011-01-14T17:52:21Z Indexed on 2011/01/14 17:53 UTC
Read the original article Hit count: 233

Filed under:
|
|
|

I'm sure I'm missing something simple. bar gets autowired in the junit test, but why doesn't bar inside foo get autowired?

@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());
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about spring