我实现了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;
}
答案 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}]