Could not instantiate bean : Constructor threw exception; nested exception is java.lang.NullPointerException

后端 未结 3 1419
自闭症患者
自闭症患者 2021-02-19 23:08
package baseDao;

public interface BaseDao {

    public void create(Object obj);
    public void delete(Object obj);
    public void update(Object obj);
    public void         


        
3条回答
  •  情歌与酒
    2021-02-19 23:57

    The problem is here:

    @Autowired
    private  SessionFactory usermanagementSessionFactory;
    private  Session session = usermanagementSessionFactory.getCurrentSession();
    

    The sessionFactory needs to be autowired, but this only happens after construction. Construction involves the second line being executed - which uses the unset factory. Hence you get a null pointer exception.

    Even though your class doesnt have a constructor, construction of an instance can still thow an exception as a result of field initialisation, as in this case.

提交回复
热议问题