Announcement Announcement Module
No announcement yet.
Where to place global configuration settings? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Where to place global configuration settings?


    I'm using Turbine as my legacy web layer, and Spring as service layer framework fetching ApplicationContext using WebApplicationContextUtils class.
    Anyway, I'm pretty happy with everything except one problem exist. If I have let's say 2 beans configured as :

    <bean id="service1" class="">
    <property name="appCode"><value>333</value></property>
    ... some other properties...

    <bean id="service2" class="">
    <property name="appCode"><value>333</value></property>
    ... some other properties...

    I would like somehow this mutual appCode property to place on some global place, thus to set this 333 value just on one place, and not having to set it on 2 places for each bean separately. Moreover, this appCode property would need somehow to be accessible to my web layer, since I see it for presentation purposes.
    Is it possible somehow ?

    Do I have to restructure my beans to use MessageSource dependency instead of plain property setter, and place such global settings in resource .property file ?


  • #2
    Where to place global configuration settings?

    Something like this?
        <!--Configurer that replaces $&#123;...&#125; placeholders with values from properties files-->
        <bean id="myDatabase" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <description>Database specific options</description>
            <property name="location">
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName">
                <description>JDBC Driver</description>
            <property name="url">
                <description>Connection string</description>
            <property name="username">
                <description>Database username</description>
            <property name="password">
                <description>Database password</description>


    • #3
      Re: Where to place global configuration settings?

      Spledid! But one more thing ...
      Since I need this same "global" settings being fetched directly from my legacy web classes for presentation purposes, is there some way of fetching them in some form like :
      somehow from BeanFactory or ApplicationContext ?



      • #4
        Just create a String (oe whatever) in the context which also is initialized to that value. It will be a one line bean definition, basically. What you might want to do instead though is put a bunch of these properties together into either a map, or a specific configuration JavaBean. Then the client is not requesting individual properties as beans, but rather the whole Map or config JavaBean. Whatever works...


        • #5
          Maybe even better idea - I could override Spring's PropertyPlaceholderConfigurer with my own, that would expose additional methods for fetching these "global" settings (placed in .properties file). Thus, one could fetch this new ExposingPlaceholderConfigurer from context, and use this new methods to fetch these settings. Of course, it's best to create some utility class that would contain this code.

          It's just that at first glance, I don't see where the hell these properties can be pulled from (in PropertyPlaceholderConfigurer) ?


          • #6
            take a look at org.springframework.beans.factory.config.Propertie sFactoryBean.