Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbctemplate not getting created in the DAO class

 
Shah Hiren
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shah Hiren
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have corrected the package names.












The service xlsxtocsv.class calls ValidationDAO .But ValidationDAO is not getting injected with jdbc template.
 
Shah Hiren
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
web.xml










 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic