I've annotated my Configuration class with @EnableJms and Spring doesn't seem to be picking up my JMS endpoint. Can someone point me in the right direction?
When I run the class I am expecting the JMS messages to start printing to the console. They don't print because it doesn't seem to be loading my JMSListener.
Here's my config class:
@Configuration
@EnableJms
public class MyConfig {
@Bean
public JndiTemplate jndiTemplate() {
JndiTemplate jndiTemplate = new JndiTemplate();
Properties jndiProps = new Properties();
jndiProps.setProperty("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
jndiProps.setProperty("java.naming.provider.url", "t3://app1.qarc1.blahblahblah.com:7201"); //
t3://serverAddress:port
jndiProps.setProperty("java.naming.security.principal", "user"); // injected from properties file username
jndiProps.setProperty("java.naming.security.credentials", "password"); //injected from properties file password
jndiTemplate.setEnvironment(jndiProps);
return jndiTemplate;
}
@Bean
public JndiDestinationResolver destinationResolver() {
JndiDestinationResolver destinationResolver = new JndiDestinationResolver();
destinationResolver.setJndiTemplate(jndiTemplate());
return destinationResolver;
}
@Bean
public JndiObjectFactoryBean jmsConnectionFactory() {
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setJndiTemplate(jndiTemplate());
jndiObjectFactoryBean.setJndiName("jms/MyQueueConnectionFactory"); // connectionFactory name.
return jndiObjectFactoryBean;
}
@Bean
public TransactionAwareConnectionFactoryProxy connectionFactoryProxy() {
return new TransactionAwareConnectionFactoryProxy((ConnectionFactory) jmsConnectionFactory().getObject());
}
@Bean
public DefaultJmsListenerContainerFactory myContainerFactory() {
DefaultJmsListenerContainerFactory factory =
new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactoryProxy());
factory.setDestinationResolver(destinationResolver());
factory.setConcurrency("1-1");
return factory;
}
}
And here's my JMS endpoint:
@Component
public class QueueMessageReceiver {
@JmsListener(containerFactory = "myContainerFactory", destination = "jms/MyQueue")
public void onMessage(
String message) {
try {
System.out.println(message);
}catch(Exception e){
e.printStackTrace();
}
}
}
And my main class:
public class App
{
public static void main( String[] args ) throws InterruptedException
{
ApplicationContext context = new AnnotationConfigApplicationContext(MyConfig.class);
Thread.sleep(1000 * 60);
}
}
Now If I take the exact same code and add this to my MyConfig then the messages start appearing:
@Bean
public QueueMessageReceiver queueMessageReceiver() {
return new QueueMessageReceiver();
}
But I shouldn't need that with the @EnableJms annotation right?