Spring 当所有 beans 都标记为惰性时,引导应用程序无法启动,因为它找不到错误通道

Spring Boot app fails to start when all beans are marked as Lazy, as it can't find an error channel

在 Spring Boot 2.2 中,您可以默认将所有 bean 标记为惰性。

如果我通过

打开它

spring.main.lazy-initialization=true

我收到以下消息:

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

Description:

A component required a bean named 'errorChannel' that could not be found.

引用此代码的相关代码是:

@MessagingGateway(errorChannel = "errorChannel")
@FunctionalInterface
public interface SomeInterface {

看起来惰性设置已停止 Spring 集成创建 errorChannel。

如何在此处将 errorChannel bean 标记为不惰性?

另外,我如何排除其他 类 在 Spring Boot 2.2 中默认不懒惰?

不过,我在其他地方遇到了一些与惰性相关的异常。 我猜你的应用程序比你在问题中说的要复杂得多。

总之有一个LazyInitializationExcludeFilter:

@Bean
public static LazyInitializationExcludeFilter integrationExcludeFilter() {
    return (beanName, beanDefinition, beanType) -> "testChannel".equals(beanName);
}

查看其 JavaDocs:

/**
 * Filter that can be used to exclude beans definitions from having their
 * {@link AbstractBeanDefinition#setLazyInit(boolean) lazy-init} set by the
 * {@link LazyInitializationBeanFactoryPostProcessor}.
 * <p>
 * Primarily intended to allow downstream projects to deal with edge-cases in which it is
 * not easy to support lazy-loading (such as in DSLs that dynamically create additional
 * beans). Adding an instance of this filter to the application context can be used for
 * these edge cases.
 * <p>
 * A typical example would be something like this:
 * <p>
 * <pre><code>
 * &#64;Bean
 * public static LazyInitializationExcludeFilter integrationLazyInitializationExcludeFilter() {
 *   return LazyInitializationExcludeFilter.forBeanTypes(IntegrationFlow.class);
 * }</code></pre>
 * <p>
 * NOTE: Beans of this type will be instantiated very early in the spring application
 * lifecycle so they should generally be declared static and not have any dependencies.
 *
 * @author Tyler Van Gorder
 * @author Philip Webb
 * @since 2.2.0
 */
@FunctionalInterface
public interface LazyInitializationExcludeFilter {

我还不知道如何从框架的角度修复它...