【问题标题】:Spring Bean injection fails on OpenShiftOpenShift 上的 Spring Bean 注入失败
【发布时间】:2017-08-24 21:28:49
【问题描述】:

我在我们的 Spring Boot 应用程序中添加了一个带有 Spring Messaging 的新 Spring Integration 配置。 该应用程序在我的 MAC 上正确部署和运行。

然而, 当部署到 OpenShift(使用 OpenJDK)或 Docker 运行时 部署失败并出现以下错误:

Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'org.springframework.messaging.MessageChannel' available:
expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations:
{@org.springframework.beans.factory.annotation.Qualifier(value=ftpChannel)}

下面是代码失败并出现相同错误的简化版本:

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.messaging.MessageChannel;
import org.springframework.stereotype.Service;


@Service
public class FtpService {

    private final MessageChannel ftpClientInboundChannel;

    public FtpService(@Qualifier("ftpChannel") MessageChannel ftpClientInboundChannel) {
        this.ftpClientInboundChannel = ftpClientInboundChannel;
    }
}

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;


@Configuration
@IntegrationComponentScan
public class FtpClientConfiguration {

    @Bean
    @ServiceActivator(inputChannel = "ftpChannel")
    public MessageHandler ftpPayableHandler() {

        return new MessageHandler() {
            @Override
            public void handleMessage(Message<?> message) throws MessagingException {

            }
        };
    }

}

【问题讨论】:

    标签: spring docker spring-boot dependency-injection openshift


    【解决方案1】:

    通过添加消息通道 bean 解决了该问题:

    @Bean
    public MessageChannel ftpChannel() {
        return new DirectChannel();
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-19
      • 2011-11-13
      • 1970-01-01
      • 2021-06-29
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      • 2020-08-11
      • 2015-01-21
      相关资源
      最近更新 更多