title: How to Override JMS connectionfactory and queues in a Spring boot application
body: <p>I am new to Spring Boot and JMS and trying to do a setup with a simple Producer class for sending a message to queue. I want to create a generic class which can work both on ActiveMQ as well as Weblogic.
  While testing with ActiveMQ, if i do a lookup with 'ConnectionFactory' and dynamicqueues it works fine.
  But when i try to do the lookup from properties file, it is throwing me a 'NameNotFound exception'.</p>
  
  <p>The queue and connection factory already exist on weblogic as well as activemq.</p>
  
  <p>Below is the code ApplicationConfig.java //setup for bean instantiation</p>
  
  <pre><code>        @Configuration
          @EnableJMS
          public class AppConfiguration{
  
          @Autowired
          private JMSProperties jmsProps;
  
          @Bean
          public InitialContex getInitialContext() throws Exception{
          InitialContext ctx = null;
          try{
          ctx = new InitialContext();}
          catch(NamingException ne){
          throw ne;
          }
          }
          return ctx;
          }
  
          @Bean
          public ConnectionFactory getconnFac(InitialContext ctx) throws Exception{
          ConnectionFactory cf = null;
          try{
          cf = (ConnectionFactory) ctx.lookup(jmsProps.getConnectionFactoryJndi());
          }
          catch(NamingException ne){
          throw ne;
          }
          return cf;
          }
  
  
          @Bean
          public Destination getDest(InitialContext ctx) throws Exception {
          Destination dest = null;
          try{
          dest = (Destination) ctx.loolup (jmsProps.getTargetQueueJndi());
          }
          catch(NamingException ne){
          throw ne;
          }
          return dest;
          }
  
  
          @Bean
          public JmsTemplate getJmsTemplate(ConnectionFactory cf){
          JmsTemplate jmsTemplate = new JmsTemplate(cf);
          return jmsTemplate;
          }
          }
  </code></pre>
  
  <p>JmsProperties.java // file to read the jms properties</p>
  
  <pre><code>        @Component
          @ConfigurationProperties
          @PropertySouce("classpath:/jms.properties")
          public class JmsProperties{
          private String targetQueueJndi;
          private String connectionFactoryJndi;
  
          public String getTargetQueueJndi(){
          return targetQueueJndi;
          }
  
          public void setTargetQueueJndi(String targetQueueJndi){
          this.targetQueueJndi = targetQueueJndi;
          }
  
          public String getConnectionFactoryJndi(){
          return connectionFactoryJndi;
          }
  
          public void setConnectionFactoryJndi(String connectionFactoryJndi){
          this.connectionFactoryJndi = connectionFactoryJndi;
          }
  
          }
  </code></pre>
  
  <p>jms.properties // file to find the actual connection factory and queue</p>
  
  <pre><code>        connection-factory.name = MQOOFDEACF
          connection-factory.local-jndi = jms/MQOOFDEACF
  
          target-queue.name = MQOOFDEAQ
          target-queue.local-jndi = jms/MQOOFDEAQ
  
  
          application-loc.properties
  
          target-queue-jndi = ${target-queue.local-jndi}
          connection-factory-jndi=${connection-factory.local-jndi}
  </code></pre>
  
  <p>Exception thrown: // exception thrown while building </p>
  
  <pre><code>caused by: org.springframework.beans.BeanInstantiationException: Failed to instatiate [javax.jms.ConnectionFactory]: Factory method 'getConnFac' threw exception; nested excetion is javax.naming.NameNotFoundException: jms/MQOOFDEACF
  </code></pre>