Spring Bean注入在OpenShift上失败

时间:2017-03-30 19:16:54

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

我在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 {

            }
        };
    }

}

1 个答案:

答案 0 :(得分:0)

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

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