title: How to create Configuration class with Beans in spring boot?
body: <p>I am converting a project done using spring jms into spring boot project. I dont know how to convert the context.xml in spring jms into the configuration class in spring boot. My context.xml is as follows</p>
  
  <pre><code>&lt;bean
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
  
      &lt;property name="location"&gt;
          &lt;value&gt;file:./config-env-receiver.properties&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="stepConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory"&gt;
      &lt;property name="hostName"&gt;
          &lt;value&gt;${mq.hostname.step}&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="port"&gt;
          &lt;value&gt;${mq.port.step}&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="channel"&gt;
          &lt;value&gt;${mq.channel.step}&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="queueManager"&gt;
          &lt;value&gt;${mq.queuemanager.step}&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="transportType"&gt;
          &lt;value&gt;1&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jmsDestination" class="com.ibm.mq.jms.MQQueue"&gt;
      &lt;constructor-arg value="${mq.queuename.step}" /&gt;
  &lt;/bean&gt;
  &lt;bean
      class="org.springframework.jms.listener.DefaultMessageListenerContainer"&gt;
      &lt;property name="connectionFactory" ref="stepConnectionFactory" /&gt;
      &lt;property name="sessionTransacted" value="true" /&gt;
      &lt;property name="destinationName" value="${mq.queuename.step}" /&gt;
      &lt;property name="exceptionListener" ref="exceptionListener" /&gt;
      &lt;property name="messageListener" ref="stepOutListenerItemCreateUpdate" /&gt;
  &lt;/bean&gt;
  &lt;bean id="exceptionListener" class="com.message.view.CustomException"&gt;      
  &lt;/bean&gt;
      &lt;bean id="stepOutListenerItemCreateUpdate"
      class="com.message.view.WMQueueMessageConsumer"&gt;
          &lt;/bean&gt;
  &lt;bean id="springConnectionFactory"
      class="org.springframework.jms.connection.SingleConnectionFactory"&gt;
      &lt;property name="targetConnectionFactory" ref="stepConnectionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jmsTemplateStep" class="org.springframework.jms.core.JmsTemplate"&gt;
      &lt;property name="connectionFactory" ref="springConnectionFactory" /&gt;
      &lt;property name="defaultDestination" ref="jmsDestination" /&gt;
  &lt;/bean&gt;
  
  &lt;context:component-scan base-package="com.message.view"&gt;
  &lt;/context:component-scan&gt;
  </code></pre>
  
  <p></p>
  
  <p>I tried creating the Application.class as follows.</p>
  
  <pre><code>package hello;
  import java.util.Arrays;
  import javax.jms.JMSException;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ImportResource;
  import org.springframework.jms.connection.SingleConnectionFactory;
  import org.springframework.jms.core.JmsTemplate;
  import org.springframework.jms.listener.DefaultMessageListenerContainer;
  import com.ibm.mq.jms.MQQueue;
  import com.ibm.mq.jms.MQQueueConnectionFactory;
  
  @SpringBootApplication
  //@ImportResource("classpath:context_receiver.xml")
  public class Application {
  
  @Autowired
  public CustomException customException;
  
  @Autowired
  public MessageListener messageListener;
  
  @Bean
  public MQQueueConnectionFactory getMQconnectionfactory(){
      MQQueueConnectionFactory mqconfactory=new MQQueueConnectionFactory();
  
      try {
          mqconfactory.setHostName("*******");
          mqconfactory.setPort(*****);
          mqconfactory.setChannel("**********");
          mqconfactory.setQueueManager("********");
          mqconfactory.setTransportType(1);
      } catch (JMSException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return mqconfactory;
  
  }
  
  @Bean
  public MQQueue getMQQueue(){
      return new MQQueue();
  } 
  
  
  
  @Bean
  public DefaultMessageListenerContainer getDefaultMessageListenerContainer(){
      DefaultMessageListenerContainer defmesliscont=new DefaultMessageListenerContainer();
      defmesliscont.setConnectionFactory(getMQconnectionfactory());
      defmesliscont.setSessionTransacted(true);
      defmesliscont.setDestinationName("********");
      defmesliscont.setExceptionListener(customException);
      defmesliscont.setMessageListener(messageListener);
      return defmesliscont;
  }
  
  @Bean
  public SingleConnectionFactory getSingleConnectionFactory(){
      SingleConnectionFactory singleConnectionFactory=new SingleConnectionFactory();
      singleConnectionFactory.setTargetConnectionFactory(getMQconnectionfactory());
      return singleConnectionFactory;
  }
  
  @Bean
  public JmsTemplate getJmsTemplate(){
      JmsTemplate jmsTemplate=new JmsTemplate();
      jmsTemplate.setConnectionFactory(getSingleConnectionFactory());
      jmsTemplate.setDefaultDestination(getMQQueue());
      return jmsTemplate;
  }
  
  public static void main(String[] args) {
      ApplicationContext ctx = SpringApplication.run(Application.class, args);
  
      System.out.println("Let's inspect the beans provided by Spring Boot:");
  
      String[] beanNames = ctx.getBeanDefinitionNames();
      Arrays.sort(beanNames);
      for (String beanName : beanNames) {
          System.out.println(beanName);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>But am getting this error.</p>
  
  <pre><code>org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: ; nested exception is java.lang.IllegalArgumentException: Attribute 'exclude' is of type [Class[]], but [String[]] was expected. Cause: 
  at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:383)
  at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:162)
  at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:296)
  at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:240)
  at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
  at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
  at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
  at hello.Application.main(Application.java:81)
  Caused by: java.lang.IllegalArgumentException: Attribute 'exclude' is of type [Class[]], but [String[]] was expected. Cause: 
  at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:117)
  at org.springframework.core.annotation.AnnotationAttributes.getStringArray(AnnotationAttributes.java:70)
  at org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.selectImports(EnableAutoConfigurationImportSelector.java:69)
  at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:379)
  ... 13 common frames omitted
  
  Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: ; nested exception is java.lang.IllegalArgumentException: Attribute 'exclude' is of type [Class[]], but [String[]] was expected. Cause: 
  at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:383)
  at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:162)
  at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:296)
  at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:240)
  at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
  at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
  at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
  at hello.Application.main(Application.java:81)
  Caused by: java.lang.IllegalArgumentException: Attribute 'exclude' is of type [Class[]], but [String[]] was expected. Cause: 
  at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:117)
  at org.springframework.core.annotation.AnnotationAttributes.getStringArray(AnnotationAttributes.java:70)
  at org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.selectImports(EnableAutoConfigurationImportSelector.java:69)
  at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:379)
  ... 13 more
  </code></pre>
  
  <p>I have even tried importing the context.xml using @ImportResource. But that too is not working. Though i prefer configuring it through the Application.class.
  Please tell me what am doing wrong. Thanks.</p>