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

时间:2012-07-06 07:53:07

标签: java spring

     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)

你能帮助我知道这个错误发生的原因吗?

2 个答案:

答案 0 :(得分:2)

  

引起:org.springframework.beans.BeanInstantiationException:无法实例化bean类[com.synechron.tom.pnl.dao.impl.PNLResultDAOImpl]:构造函数抛出异常;嵌套异常是java.lang.NullPointerException

检查构造函数中的类com.synechron.tom.pnl.dao.impl.PNLResultDAOImpl,它会抛出NullPointerException,因此spring无法初始化该bean

答案 1 :(得分:0)

如果您在PNLResultDAOImpl类中使用默认构造函数,并且您正在调用pnlBucketDAO.find(pnlBucket)方法,则可以在默认构造函数中使用@Qualifier为pnlBucketDAO注入bean。

对于前。

@Autowired(required = true)
public PNLResultDAOImpl(@Qualifier("pnlBucketDAO") BasketBallGameModel model) {
       pnlBucketDTDIndex = pnlBucketDAO.find(pnlBucket);
}