Announcement Announcement Module
No announcement yet.
ApplicationContext: initializing with a list of files Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • ApplicationContext: initializing with a list of files

    Hello out there!

    I've asked this before on the SourceForge list, but it seems to be pretty much dead. I'm completely new to Spring so I may be getting at this from an entirely wrong angle. Here's my app scenario. I'm keeping several XML files in WEB-INF/data. At startup, those files should each be digested into object hierarchies and registered with a manager objects.

    I see more or less how I could define, in applicationContext.xml, a bean for each of the hierarchies that gets initialized through a factory method. Then I could set a property of the manager bean with the list of the hierarchy beans.

    What I don't like about this, is that I'd have to explicitly, repetitively, and errorpronely define all the beans. I'd rather like to
    have a declarative way to achieve my goal. Inspired by Ant it could
    something like this

    <bean id='manager'
      <call-method name='register'>
        <mapper name='digest' class='....myapp.MyDigester'/>
        <fileset dir='.../WEB-INF/data'>
          <include name='*.xml'/>

    This is supposed to mean that
    • * register is a method taking a single argument
      * the arguments for repetitive calls are taken from a fileset
      * before the argument objects are passed to register, they are transmogrified into appropriate object hierarchies by a call to the (static) method digest.

    Of course, this is all very ad hoc and probably doesn't generalize well. I'm grateful for any suggestion.


  • #2
    Hmmmm. I like it. But, I'm an Ant fanatic.

    I would add the ability to reference bean settings. That is, singletonness, lazy-load and all that are named attribute sets. Also, I would add that in the config file, the list of POJOs to beanify are also in a ref.

    The main problem with all this of course is that this is just for simple beans that have very little DI required. Which is the whole point of IoC, IMHO. And that is where the human comes into the picture, but some of the ant stuff is very applicable. Ooops, forgot about the autowire stuff. Autowire could be used here.

    I had the idea to have an ant task that could generate even the whole config file. Just point it at a package, use a regex filter, and some reflective capability, and it will 'investigate' a package to see what could be done (we don't want to create beans from interfaces, etc). Probably only good for initial creation of stuff or prototyping.

    But, an IDE that did this with suitable wizards would be cool. Like Drag and drop classes into a context definition. I never tried it with the current spring eclipse plug-in, maybe it does this.


    • #3
      Have you tried the XDoclet plugin at
      XDoclet for this kind of thing?


      • #4
        Originally posted by khote
        Have you tried the XDoclet plugin at
        XDoclet for this kind of thing?
        I have had a look at it and I must admit that I don't understand what it does. I've been learning about J2EE development for a few weeks right now, and so far I haven't looked into XDoclet at all.

        What I do know, though, is that XDoclet works at compile-time. I'm looking for something that works at runtime.