Results 1 to 3 of 3

Thread: applicationcontext as properties file

  1. #1
    Join Date
    Jul 2010
    Posts
    5

    Default applicationcontext as properties file

    Is it possible to use the applicationContext.xml as a .properties file?
    I'd like to have all the configuration in one place and i would like to create some kind of properties bean in the applicationContext. Like so:

    PHP Code:
    <bean id="myProperties" class="Properties">
        <
    property name="name_1" value="value_1"/>
        <
    property name="name_2" value="value_2"/>
    <!-- 
    add your properties here -->
        <
    property name="name_n" value="value_n"/>
    </
    bean

    PropertiesFactoryBean is no good because then i would need an extra config file.

    OK - i just realized all i need is a bean with a property of type map, easy-peasy
    http://www.java2s.com/Code/Java/Spri...jectionMap.htm
    Last edited by Ivanana; Dec 24th, 2010 at 06:51 AM. Reason: found it!

  2. #2

    Default

    Why not use a properties file and bring that into the applicationContext? Let me know if this helps.

    Something like

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location"><value>/WEB-INF/jdbc.properties</value></property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName"><value>${jdbc.driverClassNa me}</value></property>
    <property name="url"><value>${jdbc.url}</value></property>
    <property name="username"><value>${jdbc.username}</value></property>
    <property name="password"><value>${jdbc.password}</value></property>

    </bean>

  3. #3
    Join Date
    Jul 2010
    Posts
    5

    Default

    Thanks, but the idea was to bring all config together in the applicationContext.
    Right after i posted i realized i could do this easily with <map>.
    PHP Code:
    <bean id="propertiesMap" class="com.company.project.package.MyProperties">
            <
    property name="myPropertiesMap">
                <
    map>
                    <
    entry key="property_1" value="value_1"/>
    <!-- 
    add your properties here -->
    <!--                <
    entry key="property_2" value="value_2"/>-->
    <!--                <
    entry key="property_3" value="value_3"/>-->
                </
    map>
            </
    property>
        </
    bean

Tags for this Thread

Posting Permissions

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