我可以自动装配 Spring Cloud 中的所有可用通道吗?
Can I autowire all available channels in Sprinng Cloud?
我有一个 Spring 云应用程序,我在其中定义了如下渠道:
interface MyEventAChannel {
@Output("my-event-a")
fun output(): MessageChannel
}
interface MyEventBChannel {
@Output("my-event-b")
fun output(): MessageChannel
}
是否可以自动装配所有此类频道的列表?
我在想这样的事情:
// Instead of this:
@Service
class MyService(
private val channelA: MyEventAChannel,
private val channelB: MyEventBChannel,
) {
// I want this:
@Service
class MyService(
private val channels: List<???>
) {
有什么想法吗?我再写一个接口或包装器就可以了 class.
是;这是一个例子 (Java)
@Bean
public ApplicationRunner runner(List<MessageChannel> channels) {
return args -> {
channels.stream()
.filter(ch -> ch instanceof DirectWithAttributesChannel)
.map(ch -> (DirectWithAttributesChannel) ch)
.forEach(ch -> System.out.println(ch.getAttribute("type") + ": " + ch.getComponentName()));
};
}
类型是 input
或 output
。
我有一个 Spring 云应用程序,我在其中定义了如下渠道:
interface MyEventAChannel {
@Output("my-event-a")
fun output(): MessageChannel
}
interface MyEventBChannel {
@Output("my-event-b")
fun output(): MessageChannel
}
是否可以自动装配所有此类频道的列表?
我在想这样的事情:
// Instead of this:
@Service
class MyService(
private val channelA: MyEventAChannel,
private val channelB: MyEventBChannel,
) {
// I want this:
@Service
class MyService(
private val channels: List<???>
) {
有什么想法吗?我再写一个接口或包装器就可以了 class.
是;这是一个例子 (Java)
@Bean
public ApplicationRunner runner(List<MessageChannel> channels) {
return args -> {
channels.stream()
.filter(ch -> ch instanceof DirectWithAttributesChannel)
.map(ch -> (DirectWithAttributesChannel) ch)
.forEach(ch -> System.out.println(ch.getAttribute("type") + ": " + ch.getComponentName()));
};
}
类型是 input
或 output
。