The Artima Developer Community
Sponsored Link

Java Buzz Forum
Spring: Referencing multiple bean config files

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Chris Winters

Posts: 931
Nickname: cwinters
Registered: Jul, 2003

Daytime: Java hacker; nighttime: Perl hacker; sleeptime: some of both.
Spring: Referencing multiple bean config files Posted: Feb 11, 2004 6:53 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Chris Winters.
Original Post: Spring: Referencing multiple bean config files
Feed Title: cwinters.com
Feed URL: http://www.cwinters.com/search/registrar.php?domain=jroller.com®istrar=sedopark
Feed Description: Chris Winters on Java, programming and technology, usually in that order.
Latest Java Buzz Posts
Latest Java Buzz Posts by Chris Winters
Latest Posts From cwinters.com

Advertisement
For our new project we're using Spring inside a webapp instead of deploying an EJB container. For now Spring is doing duty as a IoC container, Hibernate wrapper and minimal webapp framework. We'll probably add some AOP stuff a little later. I'm really happy with it so far and hope they're able to keep a focus on simplicity as the project matures.

So after a little initial work I wrote a new code generation system. It's much smaller than our existing one -- I'm probably not going to automate the relationship and finder methods -- and generates the domain objects, DAO interfaces and Hibernate DAO implementations from the Hibernate mapping files. It also generates the Spring bean declarations in a separate XML file.

However, I already had a bean configuration file: when deployed using the DispatcherServlet Spring looks for a /WEB-INF/${servlet_name}-servlet.xml file. This contains the Hibernate session factory declaration, datasource connection information, web application mappings, etc. So how to reference the separate XML file create during code generation? (This is probably in the docs somewhere, but I didn't see it at first glance....)

One of the nice things about Spring is that it operates like you think it should. You think: "Well, I just tell Spring to load multiple configurations." Ok, do a little research and see that it's no problem. Cool. Next: "How do I tell Spring about my configuration files?" Answer: where you initialize Spring, from the servlet configuration in web.xml:

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-dao-objects.xml,/WEB-INF/spring-servlet.xml</param-value>
    </init-param>
</servlet>

Works like a charm!

Read: Spring: Referencing multiple bean config files

Topic: Stereolab Previous Topic   Next Topic Topic: Waiting for Apple&#039;s Big Thing

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use