The Artima Developer Community
Sponsored Link

Java Buzz Forum
Spring: Telling the framework where to load beans

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: Telling the framework where to load beans Posted: Mar 1, 2004 11:08 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Chris Winters.
Original Post: Spring: Telling the framework where to load beans
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

Earlier I discussed how to refer to multiple bean definition files in the DispatcherServlet declaration in your web.xml. But you can also refer to beans not in your WAR file using the classpath: prefix:

<servlet>
    ...
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:com/optiron/cd/dao/spring-dao-objects.xml,...
        </param-value>
    </init-param>
</servlet>

I don't think this is in the docs, or if it is I missed it. (RC2 is to be released today according to Juergen.) I found it out by opening up the org.springframework.web.context.support.XmlWebApplicationContext class and browsing to the loadBeanDefinitions() method. There you see a call:

    reader.loadBeanDefinitions(getResource(this.configLocations[i]))

Ctrl-B that 'getResource()' call and you'll jump to org.springframework.context.support.AbstractApplicationContext where you can easily (it's eight lines of code) dope out how they identify items on the classpath. This process took far longer to type out here than to actually do thanks to IDEA.

What prompted this? I split out the DAO/domain objects into their own entity -- IDEA: "module"; Maven: "project" -- and I didn't want to have to copy the generated spring-dao-objects.xml file over to the webapp. Once again, Spring lets you do the right thing...

Read: Spring: Telling the framework where to load beans

Topic: Better GroovySQL Example Previous Topic   Next Topic Topic: eMarketer on Mobile Tech 2004

Sponsored Links



Google
  Web Artima.com   

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