This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Help with Spring JDBC

Mar 29th, 2011, 03:35 PM

Hello,
I am developing a web application with EclipseIDE and I am using the Struts2 and Spring3 frameworks.
I am trying to configure the web application acces to my MySQL database.
I am inexperienced with the configuration of these frameworks so I would like someone to give me a help, I'm sure it is not very complicate but I can't find what I am doing wrong.

I have configured the web.xml with the listeners ContextLoaderListener and RequestContextListener and also set the contextConfigLocation (applicationContext.xml).

In the applicationContext.xml:
- I have set the dataSource bean (driverClassName, url, username and password).
- Defined one applicationDAO bean class (it extends SimpleJdbcDaoSupport) with a property that references the dataSource bean.
- And another bean that represents the main action with a property that references the applicationDAO bean.

In the applicationDAO implementation I have implement some methods that acces the MySQL database, but I have not defined any dataSource object and either any dataSource settler because I'm pretty sure that it inherits the dataSource settler method from SimpleJdbcDaoSupport (I am extending this class).

In the main action I have defined an object that represents the applicationDAO and also its settler.

The problem is that when I debug the application, in the point of the main action that I have to use the applicationDAO object methods, it is null.

I don't know what I am missing to configure to be able to use the applicationDAO methods from the main action. I would be very very grateful to get some help.

There are lots of sample projects out there that you can look at. The petclinic is a particularly good sample to look. I also suggest writing unit and integration tests that will test your DAO layers before you try to integrate with your presentation layer.

Comment

Thank you for the information jzcfk9.
I have been looking at that samples. I have also downloaded the petclinic project and imported to my eclipse, but it is a more complex project than the one I want, anyway I have been looking it's configuration files and I can't see what I am missing.
What I would like is a simple web application with struts2 and spring3 well configured to access to my MySQL database (with spring jdbc).

If someone wants I can paste here the short code of the 4 files I mention in my first post.