English 中文(简体)
A. 按环境动态装载春风
原标题:Dynamically loading SpringBean by environment var

我试图根据正在设定的系统环境变量,说明装上春天灯的最佳途径。 我认识到,这将是一个简单的任务,使用简介,但不幸的是,使用春天2.5的Im。 因此,我XML档案中的标语是:

<bean id="updateBlogEntryListenerContainer"
          class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="concurrentConsumers" value="1"/>
        <property name="connectionFactory" ref="jmsConnectionFactory"/>
        <property name="destinationName" value="queue/updateBlogEntryQueue"/>
        <property name="messageListener" ref="updateBlogEntryMessageHandler"/>
        <property name="transactionManager" ref="transactionManager"/>
        <property name="sessionTransacted" value="true"/>
        <property name="destinationResolver" ref="destinationResolver"/>
</bean>

基本上,我只想一种办法,只根据系统环境变数而装货,否则就会忽视。 我一直在研究如何利用BeanPostProcessors和BeanFactoryPostProcessors的问题,但可以把我的inger弄在解决办法上。 在这方面的任何帮助将受到高度赞赏。 感谢!

问题回答

你们可以实施一个工厂,检查环境变数,创造实际的啤酒或一些无烟装置——如果在任何地方都没有提到工厂,则从工厂中恢复一片废墟也可能奏效。

class ListenerContainerFactory extends FactoryBean<MessageListenerContainer> {

     MessageListenerContainer getObject() {
        if (someCondition) {
            // create and return DefaultMessageListenerContainer
        } else {
            // return null or some NoOpMessageListenerContainer
        }
     }
}




相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签