aspose file tools*
The moose likes Spring and the fly likes jdbctemplate not getting created in the DAO class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "jdbctemplate not getting created in the DAO class" Watch "jdbctemplate not getting created in the DAO class" New topic
Author

jdbctemplate not getting created in the DAO class

Shah Hiren
Greenhorn

Joined: Jul 28, 2007
Posts: 21
I am getting null pointer for the jdbcTemplate even when i have auto wired it .Please suggest what could be wrong.
THe same validationDAO works from a struts action clas and query get executed as well.But it does not work from the utility class.
I tried moving it to the service package and also created Service annotation.
Please help find the errror.



THe following is the code of DAO






XML config




Thanks
Hiren


SCJP 1.4, SCWCD 1.4
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

You component scan base package of

base-package="com.k1.k2"

doesn't match the packages of your classes your posted.

On another not. k1, k2, d1, d2 are terrible package names, they tell us nothing. What the heck does it even mean. I don't want to know what it means but package structure and naming are just as important as class and interface naming.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Shah Hiren
Greenhorn

Joined: Jul 28, 2007
Posts: 21
I have corrected the package names.












The service xlsxtocsv.class calls ValidationDAO .But ValidationDAO is not getting injected with jdbc template.
Shah Hiren
Greenhorn

Joined: Jul 28, 2007
Posts: 21
web.xml










Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

And where is your <bean id="jdbcTemplate" …..

in your config file(s)

I expect that you would have one because @Autowired is required by default. So you would get an exception at ApplicationContext startup if there wasn't a jdbcTemplate defined somewhere.

Also, for your component-scan

><context:component-scan base-package="com.ericson.sales"/>


That is all you need. The include you have is redundant, unless there is other classes in your com.ericson.sale package that you do not want to be a Spring Bean and is annotated with @Component or any of the stereotype annotations like @Service.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jdbctemplate not getting created in the DAO class