Я использую модуль Spring jms в своем проекте. Моя цель - создать исполняемый файл jar, который будет запускаться другими приложениями. Я настраиваю jms на сервере weblogic, поэтому я не собираюсь использовать решение Spring-Boot.
@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 + ">");
}
}
Во время выполнения я сталкиваюсь со следующей трассировкой исключений:
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'