This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
For starters your DAO class does not require this block of code
It just needs the JdbcTemplate which already knows the datasource as you took care of that while wiring up the JdbcTemplate in your bean definitions.
Clearly JdbcTemplate is null in your UserDAO class. This leads me to believe you are probably using the new operator to create this class somewhere. In this case it is not a Spring manged bean and your JdbcTemplate will not be wired in for you. Show us how UserDAO is used.
Probably for the same reason. If I were you rather than wiring every thing up manually like that I would make use of Springs component scanner.
To use this you would annotate your services with @Service and your DAO with @Repository you could remove your service and dao beans form your configuration and replace it with
Now you can adjust that package to whatever makes sense for you but it will scan for all the stereotype annotations @Service, @Repository, @Controller, @Component etc and automatically create beans for you.
Now when you need to use them you can just autowire them in
The problem you are running into is that for some reason your are newing up these classes, when you do that they are not spring managed. Where is the entry point to your application is this a Spring-mvc application?
Ok so presumably you have some Spring controllers annotated with @Controller. These will be picked up by the component scan I mentioned. When the user logs in you are in a Spring managed bean. Any Service you call from the controller should be autowired in as I mentioned earlier, and the service itself should be annotated with @Service. Do the same for your repositories. This should solve the problem . You should never need to use the new operator when dealing with Spring managed beans. This is the purpose of dependency injection, Spring has already created your object and will provide the classes with a reference to the necessary implementations.