Announcement Announcement Module
Collapse
No announcement yet.
Best way to remove duplicate code with JmsTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Best way to remove duplicate code with JmsTemplate

    Currently i have redundant code in each of my beans but i'm not sure what the best way to abstract this out, where only the queue name changes from queue1, 2, 3.

    Code:
    	
    	<bean id="bean1" class="org.springframework.jms.core.JmsTemplate">
    		<property name="connectionFactory" ref="wlConnectionFactory"/>
    		<property name="defaultDestination">
    			<bean class="org.springframework.jndi.JndiObjectFactoryBean">
    				<property name="jndiTemplate" ref="jndiTemplate"/>
    				<property name="jndiName" value="queue1"/>
    			</bean>
    		</property>
    	</bean>
    	
    	<bean id="bean2" class="org.springframework.jms.core.JmsTemplate">
    		<property name="connectionFactory" ref="wlConnectionFactory"/>
    		<property name="defaultDestination">
    			<bean class="org.springframework.jndi.JndiObjectFactoryBean">
    				<property name="jndiTemplate" ref="jndiTemplate"/>
    				<property name="jndiName" value="queue2"/>
    			</bean>
    		</property>
    	</bean>
    	
    	<bean id="bean3" class="org.springframework.jms.core.JmsTemplate">
    		<property name="connectionFactory" ref="wlConnectionFactory"/>
    		<property name="defaultDestination">
    			<bean class="org.springframework.jndi.JndiObjectFactoryBean">
    				<property name="jndiTemplate" ref="jndiTemplate"/>
    				<property name="jndiName" value="queue3"/>
    			</bean>
    		</property>
    	</bean>

  • #2
    I suggest chapter 3.7 of the reference guide.

    Another tip would be change the lookup and let it be handled by the JmsTemplate, switch to a JndiDestinationResolver.

    All in all that would result in something like thefollowing.

    Code:
    <bean id="jmsParent" class="org.springframework.jms.core.JmsTemplate" abstract="true">
    	<property name="connectionFactory" ref="wlConnectionFactory"/>
    	<property name="destinationResolver">
    		<bean class="org.springframework.jms.support.destination.JndiDestinationResolver">
    			<property name="jndiTemplate" ref="jndiTemplate"/>
    		</bean>
    	</property>
    </bean>
    
    <bean id="bean2" class="org.springframework.jms.core.JmsTemplate" parent="jmsParent">
    	<property name="defaultDestinationName" value="queue1" />
    </bean>
    
    <bean id="bean2" class="org.springframework.jms.core.JmsTemplate" parent="jmsParent">
    	<property name="defaultDestinationName" value="queue2"/>
    </bean>
    
    <bean id="bean3" class="org.springframework.jms.core.JmsTemplate" parent="jmsParent">
    	<property name="defaultDestinationName" value="queue3"/>
    </bean>

    Comment


    • #3
      Thanks for nice thread. Duplicate Files Deleter is one of the best utility to find and remove duplicate files.

      Comment

      Working...
      X