RabbitTemplate not getting autowired in legacy project with older Spring

Viewed 718

I am trying to implement RabbitMQ in my old legacy project using plain spring.

I am trying to use like this :

@Autowire
RabbitTemplate rabbitTemplate;


public void send(){
    rabbitTemplate.ConvertAndSend("Hello")
}

But rabbitTemplate is getting as null.

Is there any alternative work around for this or I am missing something here ?

1 Answers

Typo : There is no such annotation in Spring called as @Autowire, it is @Autowired.

Please update to this :

@Autowired
RabbitTemplate rabbitTemplate;

That's why you are getting null.

Also, register the RabbitTemplate bean in the application context (XML config or java config).

Follow this Spring + RabbitMQ implementation docs for well defined example with both XML config and java config: https://docs.spring.io/spring-amqp/docs/1.4.5.RELEASE/reference/html/quick-tour.html

Related