Results 1 to 3 of 3

Thread: smth instead of PropertyPlaceholderConfigurer...

  1. #1

    Default smth instead of PropertyPlaceholderConfigurer...

    I'm using PropertyPlaceholderConfigurer to pass DB properties to my DAO layer, and it works fine. The problem is that in production environment I'm required to access all properties through a special proprietary API, which basically has methods like these:

    Code:
    String getPropertyAsString(String namespace,String name);
    ...
    So for my code it would be:

    Code:
    user = cfg.getPropertyAsString("dao","dao.username");
    How can I plug this configuration framework into Spring? Note that I cannot use it during development, since it's too tied to EJBs so I'll have to continue to get data for tests from a plain old property files.

    I wrote a gate to that system that implements BeanFactoryPostProcessor. Basically, I traverse all property values, and if it has format "GDP:ns:name", than I cut off GDP, and use ns and name to get values from config framework. But I really don't like this solution, as it requires me to handle all possible types of properties: I have to process string properties, properties, lists and may be I have even missed something. The code is not really simple.

    Is there any more simple interceptor interface, smth that accepts only one object (a property value that is going to be set to property or list or whatever) and where I can alter that value, smth like:

    Code:
    public class GDPConfigurationManagerGateway implements ??? {
       public Object preSetProperty(Object prop) {
          ...
       }
    }

  2. #2

    Default

    To clarify things: now the configuration part looks like this:

    Code:
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
    		<property name="driverClassName">
    			<value>com.ibm.db2.jcc.DB2Driver</value>
    		</property>
    		<property name="url">
    			<value>$&#123;dao.db.url&#125;</value>
    		</property>
    		<property name="username">
    			<value>$&#123;dao.db.username&#125;</value>
    		</property>
    		<property name="password">
    			<value>$&#123;dao.db.password&#125;</value>
    		</property>
    	</bean>
    I want smth like:

    Code:
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
    		<property name="driverClassName">
    			<value>com.ibm.db2.jcc.DB2Driver</value>
    		</property>
    		<property name="url">
    			<value>GDP&#58;dao&#58;db.url</value>
    		</property>
    		<property name="username">
    			<value>GDP&#58;dao&#58;db.username</value>
    		</property>
    		<property name="password">
    			<value>GDP&#58;dao&#58;db.password</value>
    		</property>
    	</bean>
    and then intercept attempt to assign, let's say, GDP:dao:db.url to a property, parse it, call the proprietary system, and assign the returned value to the property.

  3. #3
    Join Date
    Sep 2004
    Location
    Melbourne, Australia
    Posts
    54

    Default

    Hi Dozen,
    Check out spring config. The steps involved in getting a custom configuration agent going are pretty trivial. Just create a custom implementation of the AbstractPlaceholderEvaluator class for your configurtaion agent (check out CommonsPlaceholderEvaluator for an example) and then replace the PropertyPlaceholderConfigurer definition in your application context. When spring finds a ${placeholder} it will delegate to your custom placeholder evaluator allowing you to substitue the appropriate value...

    Code:
    <bean id="configurationPlaceholderProcessor"
                class="org.reactive.beans.factory.config.ConfigurationPlaceholderProcessor">
        <property name="placeholderEvaluator">
            <bean class="com.yourcompany.DozensPlaceholderEvaluator">
                ...
            </bean>
        </property>
    </bean>
    Cheers,
    Dan

Posting Permissions

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