Spring Framework Autowired Null Pointer Exception

前端 未结 3 1873
既然无缘
既然无缘 2021-01-24 23:42

I\'m learning Spring and I\'m having some problems trying to set up a relatively basic Spring project. I\'m creating an application to simply read from a database, but I\'m havi

3条回答
  •  自闭症患者
    2021-01-25 00:01

    You need to create the application context no matter if you are using xml or annotation based configuration. If your application is a web application, see this post Loading context in Spring using web.xml to load the application context

    Once you have the application you can get the bean using context.getBean() method

    Also, spring container does not manage the objects you create using new operator. In your example you need to autowire the GetCustomerEvent bean

    @Autowired GetCustomerEvent getCustomerEvent;
    //and call
    getCustomerEvent.getCustomers();
    

提交回复
热议问题