如何在我的测试中从 spring 云流中获取频道对象

How get channel object from spring cloud stream in my test

我在下面定义了一个 TestChannel 接口

public interface TestChannel {
    String CHANNEL_NAME = "test.channel";

    @Input(value = CHANNEL_NAME)
    SubscribableChannel channel();
}

我尝试在测试中自动连接此频道。

@SpringBootTest
public class TestChannelHandlerTest extends BaseTest {

    @Autowired
    private TestChannel testChannel;

    @Test
    public void someTest() {
    ...
    }
}

但是 TestChannel 中的 bean 未找到。我的问题是:如何自动连接任何频道。

@Qualifier("test.channel") 添加到 @Autowired

如果名字是testChannel就不需要了。

你在某处还需要@EnableBinding(TestChannel.class)。