Announcement Announcement Module
Collapse
No announcement yet.
applicationcontext as properties file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 06:51 AM. Reason: found it!

  • #2
    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>

    Comment


    • #3
      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

      Comment

      Working...
      X