Results 1 to 3 of 3

Thread: How to dynamically change the Bean properties

  1. #1
    Join Date
    Feb 2006
    Posts
    19

    Default How to dynamically change the Bean properties

    I configure the hsqldb setting on the xml file like the above,

    But, I want my application accepts a command arguement and then change the "url" property to

    jdbc:hsqldb:C:\RAD Workspace\client-spring\<arg_value>\db\clientcache

    therefore, my application can support multiple instances running today if needed. But, how can I do it?


    program
    ======

    appContext = new ClassPathXmlApplicationContext(new String[] {
    "config/fox-client.xml"
    });


    xml file
    ======

    <bean id="clientCacheDS" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName">
    <value>org.hsqldb.jdbcDriver</value>
    </property>
    <property name="url">
    <value>jdbc:hsqldb:C:\RAD Workspace\client-spring\db\clientcache</value>
    </property>
    <property name="username">
    <value>sa</value>
    </property>
    <property name="password">
    <value></value>
    </property>
    </bean>

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    You might want to take a look at the PropertyPlaceHolderConfigurer. That one operates on property files. That way you can have different property files for different environments.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Have you looked at PropertyPlaceholderConfigurer? This can use system proeprties to replace values. So your command line parameter -Dmyurl=blah should work fine.
    http://www.springframework.org/docs/...onfigurer.html

Posting Permissions

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