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

  • Where to place global configuration settings?

    Hi.

    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="my.company.FirstService">
    <property name="appCode"><value>333</value></property>
    ... some other properties...
    </bean>

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

    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 ?

    Cheers,
    Vjeran

  • #2
    Where to place global configuration settings?

    Something like this?
    Code:
        <!--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">
                <value>/WEB-INF/classes/hibernate.properties</value>
            </property>
        </bean>
    
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName">
                <description>JDBC Driver</description>
                <value>$&#123;hibernate.connection.driver_class&#125;</value>
            </property>
            <property name="url">
                <description>Connection string</description>
                <value>$&#123;hibernate.connection.url&#125;</value>
            </property>
            <property name="username">
                <description>Database username</description>
                <value>$&#123;hibernate.connection.username&#125;</value>
            </property>
            <property name="password">
                <description>Database password</description>
                <value>$&#123;hibernate.connection.password&#125;</value>
            </property>
        </bean>

    Comment


    • #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 :
      getProperty("globalSetting");
      somehow from BeanFactory or ApplicationContext ?

      Thanx,
      Vjeran

      Comment


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

        Comment


        • #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) ?

          Comment


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

            Comment

            Working...
            X