In meinem Frühling Boot-Anwendung null ist, ich habe eine solche @Configuration Klasse:@Autowired RabbitTemplate trotz bestehender @Bean es
@Configuration
public class AmqpConnectionConfig {
@Bean
@Primary // has to be here because of https://github.com/spring-projects/spring-boot/issues/2011
AmqpTemplate inquiryRabbitTemplate(ConnectionFactory factory) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(factory);
return rabbitTemplate;
}
@Bean
ConnectionFactory connectionFactory() {
ConnectionFactory factory = new ConnectionFactory();
// Some host/port/password setup skipped...
return new CachingConnectionFactory(factory);
}
}
und ich kann in meinen Logs sehen, dass es ganz gut läuft.
Ich habe auch einen Quartz Job, wie
@Service
public class QuartzMockingJob implements Job {
@Autowired
AmqpTemplate amqpTemplate;
public QuartzMockingJob() {
// Instances of Job must have a public no-argument constructor.
}
public void execute(JobExecutionContext context) throws JobExecutionException {
// here I create object called "mock"
if (amqpTemplate!=null) {
amqpTemplate.convertAndSend("amq.fanout", "my.routing.key", mock);
}
}
und in diesem Code amqpTemplate ist null konfiguriert ist. Ich bin verwirrt, was könnte ein Grund für dieses Verhalten sein?
Wie viele Container haben Sie konfiguriert? – hahn
Wie instanziieren Sie QuartzMockingJob? – gmaslowski
@ gmaslowski über newJob (QuartzMockingJob.class). Ich denke, das könnte das Problem verursachen. –