2016-03-23 9 views
-1

起動します。私のメッセージを受け取るための :RabbitMQの春には、私は2クラスを作成しているSpringBootでのRabbitMQを学ぼうorg.springframework.beans.factory.NoSuchBeanDefinitionException

public class Receiver { 

    private CountDownLatch latch = new CountDownLatch(1); 

    public void receiveMessage(String message) { 
     System.out.println("Received <" + message + ">"); 
     latch.countDown(); 
    } 

    public CountDownLatch getLatch() { 
     return latch; 
    } 
} 

そして、私のsecondeクラスRabbitMq2Application.java(それがspringBootApplicationです)。

@SpringBootApplication 
public class RabbitMq2Application implements CommandLineRunner{ 


    final static String queueName = "spring-boot"; 

    @Autowired 
    AnnotationConfigApplicationContext context; 

    @Autowired 
    RabbitTemplate rabbitTemplate; 

    @Bean 
    Queue queue() { 
     return new Queue(queueName, false); 
    } 

    @Bean 
    TopicExchange exchange() { 
     return new TopicExchange("spring-boot-exchange"); 
    } 

    @Bean 
    Binding binding(Queue queue, TopicExchange exchange) { 
     return BindingBuilder.bind(queue).to(exchange).with(queueName); 
    } 

    @Bean 
    SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) { 
     SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); 
     container.setConnectionFactory(connectionFactory); 
     container.setQueueNames(queueName); 
     container.setMessageListener(listenerAdapter); 
     return container; 
    } 

    @Bean 
    Receiver receiver() { 
     return new Receiver(); 
    } 

    @Bean 
    MessageListenerAdapter listenerAdapter(Receiver receiver) { 
     return new MessageListenerAdapter(receiver, "receiveMessage"); 
    } 

    public static void main(String[] args) { 
     SpringApplication.run(RabbitMq2Application.class, args); 
    } 

    @Override 
    public void run(String... args) throws Exception { 
     System.out.println("Waiting five seconds..."); 
     Thread.sleep(5000); 
     System.out.println("Sending message..."); 
     rabbitTemplate.convertAndSend(queueName, "Hello from RabbitMQ!"); 
     receiver().getLatch().await(10000, TimeUnit.MILLISECONDS); 
     context.close(); 
    } 
} 

そして、私はこのエラーを取得する:org.springframework.beans.factory.NoSuchBeanDefinitionException

私は彼が@Autowiredされているので、それはConnectionFactoryのためだと思います。

答えて

0

さらにStackTraceを共有してください。通常、その周りに多くの情報がありますNoSuchBeanDefinitionException

ConnectionFactoryクラスをインポートする場合は、他の手でチェックしてください。

@Autowired 
private ConnectionFactory connectionFactory; 

@Bean 
@ConditionalOnMissingBean(RabbitTemplate.class) 
public RabbitTemplate rabbitTemplate() { 
    return new RabbitTemplate(this.connectionFactory); 
} 

必要なタイプがある:org.springframework.amqp.rabbit.connection.ConnectionFactoryます(RabbitAutoConfiguration)のために本当に必要なすべての豆があるからです。

関連する問題