在Spring的入门指南中的以下示例中,容器bean如何获取connectionFactory? Spring Boot是否自己提供了connectionFactory?
Getting Started Messaging with Spring Redis
有5个豆子:
latch。然后接收器因为接收器构造函数需要latch.Then listenerAdapter因为它需要receiver.Both模板和容器需要connectionFactory。 在代码中,我找不到任何名为connectionFactory且使用@Bean注释的方法。
@SpringBootApplication
public class Application {
@Bean
RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
MessageListenerAdapter listenerAdapter) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.addMessageListener(listenerAdapter, new PatternTopic("chat"));
return container;
}
@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
return new MessageListenerAdapter(receiver, "receiveMessage");
}
@Bean
Receiver receiver(CountDownLatch latch) {
return new Receiver(latch);
}
@Bean
CountDownLatch latch() {
return new CountDownLatch(1);
}
@Bean
StringRedisTemplate template(RedisConnectionFactory connectionFactory) {
return new StringRedisTemplate(connectionFactory);
}
}
答案 0 :(得分:0)
它位于项目的类路径中,这就是spring boot的作用