使用带有模式名称的Spring Integration ChannelInterceptor上的注释示例来查找Bean配置

时间:2016-04-07 17:57:27

标签: spring-integration

我实现了ChannelInterceptor,并通过在xml上配置来实现它。但它不适用于基于注释的bean配置。

尝试将其付诸实践 -

@Bean
@ConditionalOnProperty(name="enableLog", havingValue="true")
@GlobalChannelInterceptor(patterns="${message.input.channel},${message.output.channel},${message.error.channel},${message.exception.channel}")
public ChannelInterceptor messageChannelInterceptor() {
    ChannelInterceptor channelInterceptor = new MessageChannelInterceptor();
    return channelInterceptor;
}

1 个答案:

答案 0 :(得分:1)

什么"不工作&#34 ;;模式?条件?

我刚刚编写了这个测试应用程序,它运行正常...

@SpringBootApplication
public class So36483811Application {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(So36483811Application.class, args);
        context.getBean("channel", QueueChannel.class).send(new GenericMessage<>("foo"));
        context.close();
    }

    @Bean
    @GlobalChannelInterceptor(patterns="*")
    public ChannelInterceptor messageChannelInterceptor() {
        ChannelInterceptor channelInterceptor = new ChannelInterceptorAdapter() {

            @Override
            public Message<?> preSend(Message<?> message, MessageChannel channel) {
                System.out.println("Here: " + message);
                return message;
            }

        };
        return channelInterceptor;
    }

    @Bean
    public QueueChannel channel() {
        return new QueueChannel();
    }

}

Here: GenericMessage [payload=foo, headers={id=89770de1-9404-1930-283c-1d74fbb06916, timestamp=1460054756722}]