@Autowired objects getting null value

后端 未结 6 1884
情话喂你
情话喂你 2021-01-12 04:29

Trying to set up a project but fail at Autowiring objects through Spring.

package se.hsr.web;

public class TestRunner {

    public static void main(String[         


        
6条回答
  •  情话喂你
    2021-01-12 04:54

    You need to retrieve the ContactDAO instance from Spring context. You are initing yourself with new keyword.

    See the below link;

    @Autowired annotation not able to inject bean in JUnit class

    or if not unit test

    ClassPathResource resource = new ClassPathResource("beans.xml");
    BeanFactory factory = new XmlBeanFactory(resource);
    beanFactory.getBean("nameOfYourBean");
    

    http://static.springsource.org/spring/docs/2.0.x/reference/beans.html

提交回复
热议问题