Results 1 to 2 of 2

Thread: Dynamically read config/context when WAR is deployed

  1. #1
    Join Date
    Dec 2009
    Posts
    9

    Default Dynamically read config/context when WAR is deployed

    I am using the spring Task Execution and scheduling framework. I would like to setup one scheduler in my application-context.xml:

    Code:
    <task:scheduler id="scheduler" pool-size="10"/>
    I have a couple of JARs (one.jar, two.jar) that are deployed in my WAR that are going to wire to the scheduler. I would like to make the existence of the JARs setup the scheduled tasks for my scheduler. I.E. if I one deploy one.jar then I only want the timers to fire for that jar.

    I can use the @Scheduled annotation to accomplish this, but then the problem is that my timer fire values are hard coded in the code.

    Is there any way that I can put config in each jar

    jar.one
    -- > one-scheduler.xml
    Code:
    <task:scheduled-tasks scheduler="myScheduler">
        <task:scheduled ref="oneObject" method="someMethod" fixed-delay="5000"/>
    </task:scheduled-tasks>
    two.jar
    -- > two-scheduler.xml
    Code:
    <task:scheduled-tasks scheduler="myScheduler">
        <task:scheduled ref="twoObject" method="someMethod" fixed-delay="10000"/>
    </task:scheduled-tasks>
    Such that spring will pick up on the fact that a jar is deployed and read its .xml file to setup the scheduled tasks?

    I think that I can 'import' those files but that is not dynamic.

    I like the idea of xml files as at build time I can run substitution to make my timers a little more configurable at build time.
    Code:
    <task:scheduled-tasks scheduler="myScheduler">
        <task:scheduled ref="twoObject" method="someMethod" fixed-delay="${some.property.value}"/>
    </task:scheduled-tasks>
    Thanks.

  2. #2
    Join Date
    Oct 2012
    Location
    Shenzhen, China
    Posts
    13

    Default

    Which version are you using? If Spring 3.1 or later, you can resort to the Profiles feature.
    Beside that option, if you build your app with ant, you could finish the substitution task in ant. Maven also has its means to do this.

Posting Permissions

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