Announcement Announcement Module
Collapse
No announcement yet.
Help with Spring JDBC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with Spring JDBC

    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.

    Thank you very much,
    alxer

  • #2
    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


    • #3
      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.

      Thank you very much for your help.
      alxer

      Comment


      • #4
        Ok, I finally fixed it.

        Looking at the struts2 spring plugin documentation (http://struts.apache.org/2.0.8/docs/spring-plugin.html) I have realised what I was doing wrong.

        I was defining wrong the action in struts.xml, I was defining it like it (with package.name of action file, "actions.Portal"):

        Code:
        <action name="Portal" class="actions.Portal">
        ...
        And as I have also a bean defined for that action (with the id "portal"), I have realised that I had to define the action like this (with the bean id in the class value):

        Code:
        <action name="Portal" class="portal">
        ...
        Thank you for your time,
        alxer

        Comment

        Working...
        X