Spring Boot 2.6 + 集成 - internalPublisherAnnotationBeanPostProcessor 循环依赖

Spring Boot 2.6 + Integration - internalPublisherAnnotationBeanPostProcessor circular dependency

我们已经升级到 2.6 Spring 引导版本。 我们也在使用 Spring 的集成(org.springframework.boot:spring-boot-starter-integration)。

当我们尝试启动应用程序时,我们得到:

***************************
APPLICATION FAILED TO START
***************************

Description:

The dependencies of some of the beans in the application context form a cycle:

┌──->──┐
|  org.springframework.integration.internalPublisherAnnotationBeanPostProcessor
└──<-──┘

我们能够使用干净的 Spring 启动应用程序重现该问题:

DemoApplication.java

package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.config.EnablePublisher;

@EnableIntegration
@EnablePublisher
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

build.gradle

plugins {
    id 'org.springframework.boot' version '2.6.1'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

有没有人暗示可能会出现什么问题?可能缺少一些额外的配置

最近已修复:https://github.com/spring-projects/spring-integration/issues/3694

下周将发布即将到来的 Spring 启动 2.6.2

作为解决方法,您可以添加此 bean,而不是 @EnablePublisher

@Bean(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME)
static PublisherAnnotationBeanPostProcessor publisherAnnotationBeanPostProcessor() {
    return new PublisherAnnotationBeanPostProcessor() {

        @Override
        public void afterPropertiesSet() {

        }

    };
}

它的 afterPropertiesSet() 中有 this.beanFactory.getBean(PublisherAnnotationBeanPostProcessor.class) 是个问题。所以,为了减轻循环,我们只需要摆脱它!