警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'users' defined in class path resource [EntityContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [Entity.Users]: Constructor threw exception; nested exception is java.lang.NullPointerException
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'users' defined in class path resource [EntityContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [Entity.Users]: Constructor threw exception; nested exception is java.lang.NullPointerException
报这个错的原因是:JAVA中的构造方法的优先级是要高于依赖注入的,所以还没有注入的情况下使用就会报空指针异常,意思是这个对象还没有被实例化就使用了相应的方法(只有静态方法才能在不实例化的情况下使用)。
解决的思路:不要在构造方法中调用依赖注入的对象,通过其他方式实现构造方法。