Java 在SpringJMS模块中获取BeanNotOfRequiredTypeException

Java 在SpringJMS模块中获取BeanNotOfRequiredTypeException,java,weblogic12c,spring-jms,Java,Weblogic12c,Spring Jms,我在我的项目中使用Spring jms模块。我的目标是创建一个可执行的jar文件,该文件将由其他应用程序触发。我在weblogic server中配置jms,因此,我不打算使用Spring引导解决方案 @Configuration @ComponentScan(basePackages = "com.myapp") @EnableJms public class MyApp { public static void main(String[] args) { ApplicationC

我在我的项目中使用Spring jms模块。我的目标是创建一个可执行的jar文件,该文件将由其他应用程序触发。我在weblogic server中配置jms,因此,我不打算使用Spring引导解决方案

@Configuration
@ComponentScan(basePackages = "com.myapp")
@EnableJms
public class MyApp {
  public static void main(String[] args) {
    ApplicationContext context  = null;
    try {
          context = new AnnotationConfigApplicationContext(MyApp.class);
          MyBeanProvider beanProvider = context.getBean(MyBeanProvider.class);
          System.out.println(beanProvider);
    } catch (BeansException e) {
        e.printStackTrace();
    } finally{
        ((AbstractApplicationContext)context).close();
      }
    }
 }

@Component
public class MyBeanProvider {

  @Bean
  public JndiTemplate getJndiTemplate() {
     JndiTemplate jndiTemplate = new JndiTemplate();
     Properties properties = new Properties();
     properties.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
     properties.put("java.naming.provider.url", "t3://localhost:7001");
     jndiTemplate.setEnvironment(properties);
     return jndiTemplate;
   }

  @Bean(value="MyBeanConnectionFactory")
  public JndiObjectFactoryBean getConnectionFactory() {
      JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
    jndiObjectFactoryBean.setJndiTemplate(getJndiTemplate()); 
    jndiObjectFactoryBean.setJndiName("jms/MyAppConnectionFactory");
    return jndiObjectFactoryBean;
  }

  @Bean
  public JndiDestinationResolver getDestinationResolver() {
      JndiDestinationResolver jndiDestinationResolver = new JndiDestinationResolver();
      jndiDestinationResolver.setCache(true); 
      jndiDestinationResolver.setJndiTemplate(getJndiTemplate());
      return jndiDestinationResolver;
   }

   @Bean
   public JmsTemplate getJmsTemplate() {
      JmsTemplate jmsTemplate = new JmsTemplate();
      jmsTemplate.setConnectionFactory
      ((javax.jms.ConnectionFactory)getConnectionFactory().getObject());
            jmsTemplate.setDestinationResolver(getDestinationResolver()); 
            return jmsTemplate;
        }
      }
    }
我有一个消息接收器类,如下所示:

 @Component
 public class MyBeanMessageReceiver {
  @JmsListener(destination = "jms/queue/MyAppMessageQueue",containerFactory="MyBeanConnectionFactory")
  public void receiveMessage(String message) {
    System.out.println("Received <" + message + ">");
  }
 }
containerFactory=“MyBeanConnectionFactory”

containerFactory
属性必须引用
JmsListenerContainerFactory
而不是
ConnectionFactory

容器工厂依次获得对连接工厂的引用

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyBeanMessageReceiver' defined in file : Initialization of bean failed; nested exception is  
 org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'MyBeanConnectionFactory' is expected to be of type  
'org.springframework.jms.config.JmsListenerContainerFactory' but was actually of type 'weblogic.jms.client.JMSXAConnectionFactory'