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

Ele*_*tos 8 java spring spring-integration spring-boot

我们已升级到 2.6 Spring boot 版本。\n我们还使用 Spring 的 Integration (org.springframework.boot:spring-boot-starter-integration)。

\n

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

\n
***************************\nAPPLICATION FAILED TO START\n***************************\n\nDescription:\n\nThe dependencies of some of the beans in the application context form a cycle:\n\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80->\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n|  org.springframework.integration.internalPublisherAnnotationBeanPostProcessor\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80<-\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

演示应用程序.java

\n
package com.example.demo;\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.integration.config.EnableIntegration;\nimport org.springframework.integration.config.EnablePublisher;\n\n@EnableIntegration\n@EnablePublisher\n@SpringBootApplication\npublic class DemoApplication {\n\n    public static void main(String[] args) {\n        SpringApplication.run(DemoApplication.class, args);\n    }\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n

构建.gradle

\n
plugins {\n    id 'org.springframework.boot' version '2.6.1'\n    id 'io.spring.dependency-management' version '1.0.11.RELEASE'\n    id 'java'\n}\n
Run Code Online (Sandbox Code Playgroud)\n

有人知道可能会出什么问题吗?也许缺少一些额外的配置

\n

Art*_*lan 3

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

将于下周针对即将推出的 Spring Boot 发布2.6.2

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

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

        @Override
        public void afterPropertiesSet() {

        }

    };
}
Run Code Online (Sandbox Code Playgroud)

问题是它this.beanFactory.getBean(PublisherAnnotationBeanPostProcessor.class)afterPropertiesSet(). 因此,为了缓解循环,我们只需摆脱它即可!