Spring integration 如何在spring集成网关上使用AOP?

Spring integration 如何在spring集成网关上使用AOP?,spring-integration,spring-aop,Spring Integration,Spring Aop,我想通过AOP拦截所有spring集成网关 有可能吗?若并没有,那个么记录输入对象进入网关的最佳方式是什么 @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext public class AdviceExample { @Autowired private TestGateway testGateway; @Test public void testIt() { Sy

我想通过AOP拦截所有spring集成网关

有可能吗?若并没有,那个么记录输入对象进入网关的最佳方式是什么

@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class AdviceExample {

  @Autowired
  private TestGateway testGateway;

  @Test
  public void testIt() {
    System.out.println(this.testGateway.testIt("foo"));
  }


  @MessagingGateway
  public interface TestGateway {

    @Gateway(requestChannel = "testChannel")
    @CustomAnnotation
    String testIt(String payload);

  }

  @Configuration
  @EnableIntegration
  @IntegrationComponentScan
  @EnableMessageHistory
  @EnableAspectJAutoProxy
  public static class ContextConfiguration {
    LoggingHandler logger = new LoggingHandler(LoggingHandler.Level.INFO.name());

    @Bean
    public IntegrationFlow testFlow() {
      return IntegrationFlows.from("testChannel")
                             .transform("payload.toUpperCase()")
                             .channel("testChannel")
                             .transform("payload.concat(' Manoj')")
                             .channel("testChannel")
                             .handle(logger)
                             .get();
    }

    @Bean
    public GatewayAdvice gtwyAdvice(){
      return new GatewayAdvice();
    }

  }

  @Retention(value = RetentionPolicy.RUNTIME)
  @Target(value = ElementType.METHOD)
  @Inherited
  public @interface CustomAnnotation{

  }

  @Aspect
  public static class GatewayAdvice {

    @Before("execution(* advice.AdviceExample.TestGateway.testIt(*))")
    public void beforeAdvice() {
        System.out.println("Before advice called...");
    }

    @Before("@annotation(advice.AdviceExample.CustomAnnotation)")
    public void beforeAnnotationAdvice() {
      System.out.println("Before annotation advice called...");
  }
  }

}

是的,你能做到。看看标准。由于所有这些
@Gateway
最终都是bean,因此您可以根据它们的bean名称和特定方法(如果有)为它们添加任何
建议。例如,我们经常建议对网关的方法使用
@Transactional
。这正是“如何在集成网关上使用AOP”的示例。

请更具体一些。在这件事上分享一些PoC。我恐怕回答错了。虽然它在其他地方可能有用…我想在调用网关之前和之后做一些常见的业务逻辑。哪些网关?HTTP、JMS、JDBC?或者仅仅是那些基于接口代理的?我们正在使用@Gateway创建的自定义网关..谢谢,它可以工作,但是注释风格的建议不起作用。如果您看到我上面的代码beforeAnnotationAdvice没有被调用,但是beforeAdvice被调用。这是因为注释是不可继承的?