Results 1 to 3 of 3

Thread: Best way to remove duplicate code with JmsTemplate

  1. #1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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>
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Dec 2012
    Posts
    1

    Default

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

Posting Permissions

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