Results 1 to 6 of 6

Thread: Where to place global configuration settings?

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    8

    Default 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>

  3. #3

    Default 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

  4. #4
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    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...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  5. #5

    Default

    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. #6
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    take a look at org.springframework.beans.factory.config.Propertie sFactoryBean.
    HTH.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

Similar Threads

  1. Dynamic Property Configuration
    By fenrick in forum Container
    Replies: 3
    Last Post: May 12th, 2006, 02:38 AM
  2. Getting application configuration settings from DB
    By too_many_details in forum Data
    Replies: 1
    Last Post: May 6th, 2005, 07:42 AM
  3. Configuration / Settings Best Practice?
    By lukasbradley in forum Container
    Replies: 1
    Last Post: Mar 8th, 2005, 12:30 PM
  4. Eclipse 3.0 compiler settings for Spring build?
    By jbetancourt in forum Architecture
    Replies: 4
    Last Post: Oct 5th, 2004, 03:41 PM
  5. Replies: 5
    Last Post: Aug 27th, 2004, 07:13 PM

Posting Permissions

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