Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何通过应用程序上下文将接口实例注释为服务_Java_Spring_Spring Boot_Spring Integration - Fatal编程技术网

Java 如何通过应用程序上下文将接口实例注释为服务

Java 如何通过应用程序上下文将接口实例注释为服务,java,spring,spring-boot,spring-integration,Java,Spring,Spring Boot,Spring Integration,我已经使用spring编写了一个库,用于非spring和基于spring引导的应用程序 我使用消息网关将集成流公开为普通的旧java接口,供其他类使用 import org.springframework.messaging.Message; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @Service public interfac

我已经使用spring编写了一个库,用于非spring和基于spring引导的应用程序

我使用消息网关将集成流公开为普通的旧java接口,供其他类使用

import org.springframework.messaging.Message;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public interface SwiftalkKafkaGateway {

    @Async
    void publish(Message<?> message);
}
带着错误

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.foo.cloud.swiftalk.SwiftalkKafkaGateway' available
这是由于

21:37:42.003 [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Ignored because not a concrete top-level class: URL [jar:file:/Users/anadimishra/.m2/repository/com/foo/cloud/swiftalk-kafka-client/1.0.0-SNAPSHOT/swiftalk-kafka-client-1.0.0-SNAPSHOT-jar-with-dependencies.jar!/com/foo/cloud/swiftalk/SwiftalkKafkaGateway.class]
如何在非spring环境中使用此服务的实例

更新

我使用这个的集成流程

@Bean
public IntegrationFlow kafkaPublisherFlow(KafkaProducerMessageHandler<String, String> kafkaProducerMessageHandler,
                                          RequestHandlerRetryAdvice retryAdvice,
                                          ExecutorChannel kafkaPublishChannel) {
    return IntegrationFlows.from(SwiftalkKafkaGateway.class)
            .channel(kafkaPublishChannel)
            .handle(kafkaProducerMessageHandler, e -> e.advice(retryAdvice))
            .get();
}
@Bean
公共集成流KafkapPublisherFlow(KafkapProducerMessageHandler KafkapProducerMessageHandler,
RequestHandlerRetryAdvice retryAdvice,
执行者频道(卡夫卡普公共频道){
返回IntegrationFlows.from(SwiftalkKafkaGateway.class)
.频道(卡夫卡公共频道)
.handle(kafkaProducerMessageHandler,e->e.advice(retryAdvice))
.get();
}

我们的想法是能够在spring boot和非spring boot应用程序中使用此kafka发布服务器的错误处理和幂等操作代码。

如果您想使用Sprint boot的
@EnableAutoConfiguration,您应该使用
SpringApplication
SpringApplicationBuilder
来创建应用程序上下文,未创建
注释ConfigApplicationContext`.

您是否在其中一个
@配置
类上启用了
@集成
?另外,显示集成流程。嘿,Gary,我正在使用
@EnableAutoConfiguration
我还需要把
@enableeintegration
放进去吗
@EnableAutoConfiguration
用于Spring引导,您不使用它,如果您想要自动配置,您应该使用
SpringApplication
SpringApplicationBuilder
来创建应用程序上下文,没有创建
注释ConfigApplicationContext
SpringApplicationBuilder
修复了它,谢谢!
21:37:42.003 [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Ignored because not a concrete top-level class: URL [jar:file:/Users/anadimishra/.m2/repository/com/foo/cloud/swiftalk-kafka-client/1.0.0-SNAPSHOT/swiftalk-kafka-client-1.0.0-SNAPSHOT-jar-with-dependencies.jar!/com/foo/cloud/swiftalk/SwiftalkKafkaGateway.class]
@Bean
public IntegrationFlow kafkaPublisherFlow(KafkaProducerMessageHandler<String, String> kafkaProducerMessageHandler,
                                          RequestHandlerRetryAdvice retryAdvice,
                                          ExecutorChannel kafkaPublishChannel) {
    return IntegrationFlows.from(SwiftalkKafkaGateway.class)
            .channel(kafkaPublishChannel)
            .handle(kafkaProducerMessageHandler, e -> e.advice(retryAdvice))
            .get();
}