• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error in bean creation - JDBC Template

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Vivek Murugesan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply!!

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





 
Vivek Murugesan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured the issue.
jdbcTemplate has just been declared but not instantiated. Hence the NPE.

Thanks!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic