Results 1 to 7 of 7

Thread: Injecting in bean class names

  1. #1
    Join Date
    Sep 2004
    Posts
    602

    Default Injecting in bean class names

    Is it possible to do something like this:

    <bean id="transactionManager"
    class="${transaction.manager.class}">

    .....

    </bean>

    I want the transaction manager class to be configurable at deployment time, so I want to set the class name from a properties file.

    The above doesn't work as it doesn't recognize the fact that I am trying to substitute in a property value.

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I think your problem here is that the PropertyPlaceholderConfigurer is a BeanFactoryPostProcessor. It's therefore too early in the whole process for this to work.

  3. #3
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    As Karl stated, this does not work. However, maybe it's possible to create a proxy class that delegates to a real PlatformTransactionManager and allows for runtime initialization (perhaps based on a properties file or the like).

    Regards,
    Andreas

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I was wondering the same thing, wouldn't a ProxyFactoryBean work? Just need to set the targetName dynamically.
    http://www.springframework.org/docs/...ctoryBean.html

  5. #5
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    I rather thought of a "real" class, because of the dynamic selection.
    But if the target name could be set via PropertyPlaceholderConfigurer that should work as well.

    Regards,
    Andreas

  6. #6
    Join Date
    Sep 2004
    Posts
    602

    Default

    Quote Originally Posted by Andreas Senft View Post
    I rather thought of a "real" class, because of the dynamic selection.
    But if the target name could be set via PropertyPlaceholderConfigurer that should work as well.

    Regards,
    Andreas
    Thanks for the suggestions - I am reading them honest, just have not have had time to test things out. Basically I want a configurable transaction manager that I can switch depending on whether I am running in a clustered or single node environment, so I want the class of the transaction manager to be soft coded.

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Wouldn't something like this work?
    Code:
    <bean id="transactionManager" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="target">
            <bean class="${transaction.manager">
                <property name="dataSource" ref="dataSource"/>
            </bean>
        </property>
    </bean>

Posting Permissions

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