Results 1 to 3 of 3

Thread: How to restrict/standardise Spring usage in many project

  1. #1
    Join Date
    Feb 2007
    Posts
    5

    Default How to restrict/standardise Spring usage in many project

    Hello,

    I work for a bank and we will build many applications using spring 3.x. We need force the use of common folders to all applications and to impose how configurations will be loaded.

    - We have a System Property ${rootConfig}for the base dir of all config files.
    - Each application will have to put a property file in there rootclasspath named ‘mybank.properties’ containing a property “appName=myApp”. This property will be loaded using the PropertyPlaceholderConfigurer. This work Fine.

    To locate the config files all Application will have to concatenate both placeholder: ${rootConfig}/${appName}

    Question 1: How can I provide a new Place Holders properties to the ApplicationContext so that programmers will only have to use : ${appConfig} (which will be the concatenation of ${rootConfig}/${appName}. Do I have to create a Custom PropertyPlaceholderConfigurer ? I would like to provide other dynamically created properties that programmers can use as placeholders.

    Question 2: To load a property file, we would like to check if the file exist under the ${appConfig} folder, is not, load it from the root classpath. How can I implement this behaviour using the Resources Class (i.e. ResourceLoader, PatternResolver, LoaderAware)? Do I have to build a custom ResourceLoader?

    Thank you.

  2. #2
    Join Date
    Feb 2007
    Posts
    5

    Default Custom Resource

    Hello

    I have found my answer for question 1. Using this config will do the trick:
    Code:
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>classpath:nbfg.properties</value>
        </property>
      <property name="properties"><value>appConfDir=${aSystemProperty}/${appName}/ </value>
     </property></bean>
    Now for my Question 2: When I load config files, how can I use Resources to check in a global folder if the file is there, if not, check in the root classpath.. Should I implement a Resource Loader or ResourceLoaderAware?

    Thank you

  3. #3
    Join Date
    Sep 2009
    Location
    Vilnius, Lithuania
    Posts
    118

    Default

    I suppose you could have two PropertyPlaceholders and specify their "order" so that application-specific properties can override global properties.

    If application-specific properties file is optional, you should set ignore-resource-not-found="true" so that you don't get an initialization exception.

    Code:
    <context:property-placeholder order="1" location="file:/path-to-root-config/app-config.properties"
        ignore-resource-not-found="true"/>
    
    <context:property-placeholder order="2" location="classpath:nbfg.properties"/>
    However, system path to properties file must be static, i.e. your application must know exactly where its properties file resides.

Posting Permissions

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