This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Spring and the fly likes error in bean creation - JDBC Template Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "error in bean creation - JDBC Template" Watch "error in bean creation - JDBC Template" New topic
Author

error in bean creation - JDBC Template

Vivek Murugesan
Greenhorn

Joined: Apr 09, 2009
Posts: 9
I'm a new to spring and trying few sample codes in spring . When I try to access DB (Oracle) using JDBC Template. It complies without any issues, but throws the below runtime exception.

My App-context xml file is



I use the following jars.
spring.jar
spring-core.jar
spring-jdbc.jar
ojdbc.jar
commons-dbcp.jar
commons-logging.jar
commons-pool.jar

The URL values are correct, I'm able to establish connection using JDBC.
I tried running this (as a stand lone App) using eclipse and ANT scripts as well. But getting the same error.


[java] Oct 21, 2009 9:51:19 AM org.springframework.beans.factory.xml.XmlBea
nDefinitionReader loadBeanDefinitions
[java] INFO: Loading XML bean definitions from class path resource [sampleD
AO.xml]
[java] Exception in thread "main" org.springframework.beans.factory.BeanCre
ationException: Error creating bean with name 'sampleDAO' defined in class path
resource [sampleDAO.xml]: Error setting property values; nested exception is org
.springframework.beans.PropertyBatchUpdateExceptio n; nested PropertyAccessExcept
ions (1) are:
[java] PropertyAccessException 1: org.springframework.beans.MethodInvocatio
nException: Property 'dataSource' threw exception; nested exception is java.lang
.NullPointerException
[java] at org.springframework.beans.factory.support.Abstract AutowireCap
ableBeanFactory.applyPropertyValues(AbstractAutowi reCapableBeanFactory.java:1243
)
[java] at org.springframework.beans.factory.support.Abstract AutowireCap
ableBeanFactory.populateBean(AbstractAutowireCapab leBeanFactory.java:978)
[java] at org.springframework.beans.factory.support.Abstract AutowireCap
ableBeanFactory.doCreateBean(AbstractAutowireCapab leBeanFactory.java:462)
[java] at org.springframework.beans.factory.support.Abstract AutowireCap
ableBeanFactory$1.run(AbstractAutowireCapableBeanF actory.java:404)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at org.springframework.beans.factory.support.Abstract AutowireCap
ableBeanFactory.createBean(AbstractAutowireCapable BeanFactory.java:375)
[java] at org.springframework.beans.factory.support.Abstract BeanFactory
$1.getObject(AbstractBeanFactory.java:263)
[java] at org.springframework.beans.factory.support.DefaultS ingletonBea
nRegistry.getSingleton(DefaultSingletonBeanRegistr y.java:170)
[java] at org.springframework.beans.factory.support.Abstract BeanFactory
.doGetBean(AbstractBeanFactory.java:260)
[java] at org.springframework.beans.factory.support.Abstract BeanFactory
.getBean(AbstractBeanFactory.java:184)
[java] at org.springframework.beans.factory.support.Abstract BeanFactory
.getBean(AbstractBeanFactory.java:163)
[java] at com.sample.dao.SampleDAOClient.main(Unknown Source)
[java] Caused by: org.springframework.beans.PropertyBatchUpdateExcep tion; n
ested PropertyAccessExceptions (1) are:
[java] PropertyAccessException 1: org.springframework.beans.MethodInvocatio
nException: Property 'dataSource' threw exception; nested exception is java.lang
.NullPointerException
[java] at org.springframework.beans.AbstractPropertyAccessor .setPropert
yValues(AbstractPropertyAccessor.java:104)


Thanks for any help!!
Vivek
Ram Para
Ranch Hand

Joined: Jul 09, 2008
Posts: 50
You need to configure jdbcTemplate also like this

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="lazyInit">
<value>true</value>
</property>
</bean>

Ram Parashar
http://doinfinite.com
Vivek Murugesan
Greenhorn

Joined: Apr 09, 2009
Posts: 9
Thanks for the reply!!

I'm injecting the datasource in xml and setting it in the implementation.





Vivek Murugesan
Greenhorn

Joined: Apr 09, 2009
Posts: 9
I figured the issue.
jdbcTemplate has just been declared but not instantiated. Hence the NPE.

Thanks!!
 
GeeCON Prague 2014
 
subject: error in bean creation - JDBC Template