Java 获取错误org.springframework.beans.BeanInstantiationException:

Java 获取错误org.springframework.beans.BeanInstantiationException:,java,spring,Java,Spring,你能帮我知道为什么会发生这个错误吗 导致的原因:org.springframework.beans.beans实例化异常:无法实例化bean类[com.synechron.tom.pnl.dao.impl.PNLResultDAOImpl]:构造函数引发异常;嵌套异常是java.lang.NullPointerException 检查类的构造函数com.synechron.tom.pnl.dao.impl.PNLResultDAOImpl,如果在PNLResultDAOImpl类中使用默认构造函

你能帮我知道为什么会发生这个错误吗

导致的原因:org.springframework.beans.beans实例化异常:无法实例化bean类[com.synechron.tom.pnl.dao.impl.PNLResultDAOImpl]:构造函数引发异常;嵌套异常是java.lang.NullPointerException


检查类的构造函数
com.synechron.tom.pnl.dao.impl.PNLResultDAOImpl
,如果在PNLResultDAOImpl类中使用默认构造函数并从中调用pnlBucketDAO.find(pnlBucket),它会抛出NullPointerException,因此spring无法初始化该bean方法,然后您可以在默认构造函数中使用@Qualifier为pnlBucketDAO注入bean

例如

     org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PNLResultDAOImpl' defined in file [C:\EclipseWS1\SpringJDBCExample\target\classes\com\synechron\tom\pnl\dao\impl\PNLResultDAOImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.synechron.tom.pnl.dao.impl.PNLResultDAOImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
    at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
    ... 24 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.synechron.tom.pnl.dao.impl.PNLResultDAOImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)

PNLResultDAOImpl
添加一些代码。正如@Jigar指出的,它的构造函数有问题。你得到了错误:pnlBucketDTDIndex=pnlBucketDAO.find(pnlBucket);但我已经使用@autowired创建了pnlBucketDAO对象,并且还为它提供了getter和setter
@Autowired(required = true)
public PNLResultDAOImpl(@Qualifier("pnlBucketDAO") BasketBallGameModel model) {
       pnlBucketDTDIndex = pnlBucketDAO.find(pnlBucket);
}