Results 1 to 3 of 3
  1. #1
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default Instantiation of bean failed; BeanInstantiationException

    I am working on a tutorial and I running a JUnit test on a Java Application that incorporates Spring, JDBC, and Log4j. When I run the JUnit test, I am getting the following error message:

    Java Code:
    Error creating bean with name 'userDAO' defined in file [C:\SpringsDAO\springJdbcDemoTest\config\appContext.xml]: 
    Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: 
    Could not instantiate bean class [user.DAO.Impl.UserDAOImpl]: 
    Constructor threw exception; nested exception is java.lang.NullPointerException

    I have reviewed the code several times and I can not determine why the bean is not be instantiated. I am new to Spring, java beans, Log4j, and JUnit testing so there could be something that I am not understanding. I have verified that the spelling of the bean is correct throughout the application. There are no other noticeable errors.

    Please find below the xml file:
    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    	destroy-method="close">
    	<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    	<property name="url" value="jdbc:mysql://127.0.0.1:3307/test"/>
    	<property name="username" value="root"/>
    	<property name="password" value="sesame"/>
    	<property name="maxActive" value="10"/>
    	<property name="maxIdle" value="5"/>
    	<property name="minIdle" value="1"/>
    	<property name="poolPreparedStatements" value="true"/>
    	<property name="initialSize" value="1"/>
    	</bean>
    	
    	<bean id= "transactionManager" class= "org.springframework.jdbc.datasource.DataSourceTransactionManager">
    	<property name= "dataSource" ref= "dataSource"/>
    	</bean>
    	
    	<bean id= "userDAO" class="user.DAO.Impl.UserDAOImpl">
    	<property name= "transactionManager" ref= "transactionManager"/>
    	</bean>
    	
    	
    </beans>
    I have also attached the xml file and the test class that contains the bean (userDAO).

    Thanks for your help in advance.

    Best regards,

    littleone
    Attached Files Attached Files

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Instantiation of bean failed; BeanInstantiationException

    Sounds like the null pointer is happening in the UserDAOImpl class itself. You do have a UserDAOImpl.java file right? Look in there for your null pointer - perhaps you didn't initialize something?

  3. #3
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default Re: Instantiation of bean failed; BeanInstantiationException

    I looked in the class but I did not see anything. I have attached the UserDAOImpl.java file.
    Attached Files Attached Files

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2011, 08:55 AM
  2. Instantiation order
    By Jeremy720 in forum New To Java
    Replies: 3
    Last Post: 07-17-2009, 04:19 PM
  3. UREGENT-accessing session bean ok but entity bean
    By parimal in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-28-2008, 02:34 PM
  4. instantiation
    By Camden in forum New To Java
    Replies: 1
    Last Post: 03-02-2008, 05:44 PM
  5. Instantiation
    By kavithas in forum New To Java
    Replies: 2
    Last Post: 12-05-2007, 05:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •