Results 1 to 3 of 3

Thread: Unable to have separate config file for Hibernate/DAO beans

  1. #1
    Join Date
    Dec 2004
    Location
    Asheville, NC
    Posts
    82

    Default Unable to have separate config file for Hibernate/DAO beans

    I am developing an example Spring MVC application which is a variation of what is described in the Spring MVC step-by-step tutorial. I have a Spring/Hibernate DAO class which is working well and I want to use this as a property of my Controller class for use within its handleRequest() method. In this Controller class I have a DAO private member, and a setter method for Spring to be able to set this property. I have the Spring wiring configuration split into two files, myapp-data.xml and myapp-servlet.xml.

    The trouble is that when I run the application Spring croaks upon initializing the Controller bean because it can't find the definition for the DAO bean. It somehow knows how to find myapp-servlet.xml for the configuration of the Controller and ViewResolver beans, but it doesn't know to look for myapp-data.xml for the configuration of the DAO and HibernateTemplate beans.

    Am I correct in assuming that I should have all Spring configuration files (in this case myapp-data.xml and myapp-servlet.xml) in the WEB-INF directory? If not then what is the most common or best place for these Spring config files? Perhaps the non-MVC config files should go elsewhere?

    How does Spring magically know to look for myapp-servlet.xml for the configuration of the MVC components? I never specify this anywhere, so is this is a default convention?

    For now I can get around the trouble by putting all of the Spring bean configuration into the myapp-servlet.xml, but I'd like to be able to split these apart as recommended in "Spring in Action". Can anyone sugget how I should go about doing this?

    Thanks in advance for any suggestions.


    --James

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    James,

    You don't need to put all your configuration files in /WEB-INF/ but that is often what people will do. Check out the Petclinic sample application to see how multiple configuration files can be loaded - specifically check out the configuration for web.xml.

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  3. #3
    Join Date
    Dec 2004
    Location
    Asheville, NC
    Posts
    82

    Default

    Thanks Rob.

    I also found a good explanation of this approach on pages 273-275 of "Spring in Action".


    --James

Similar Threads

  1. Saving large files to a db using hibernate?
    By Dan Washusen in forum Data
    Replies: 10
    Last Post: Sep 20th, 2006, 12:18 PM
  2. Beandoc crashing (on its samples!)
    By aaime in forum Container
    Replies: 17
    Last Post: Oct 7th, 2005, 07:21 AM
  3. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  4. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  5. Replies: 1
    Last Post: Jan 20th, 2005, 03:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •