gpt4 book ai didi

java - Spring 集成: gateway bean not found

转载 作者:行者123 更新时间:2023-12-01 04:40:55 24 4
gpt4 key购买 nike

我尝试在不同的 jar 中使用 spring 集成。在A.jar si-context.xml中:

    <context:annotation-config />
<int:annotation-config />

<int:channel id="upperServiceChannel">
<int:priority-queue />
</int:channel>

<int:gateway id="upperGateway" default-request-timeout="5000"
default-reply-timeout="5000" default-request-channel="upperServiceChannel"
service-interface="com.company.proj.gw.IUpperStringConversation">
<int:method name="toUpperCase" />
</int:gateway>


<bean id="toUpperCaseService" class="com.company.proj.service.ToUpperCaseService" />
<int:service-activator id="serviceActivatorToUpperCase"
input-channel="upperServiceChannel" method="toUpperCase" ref="toUpperCaseService" />

<int:poller id="poller" default="true" fixed-delay="1000" />
<context:component-scan base-package="com.company"/>

在一个 bean 中我使用这个网关:

 @Component(value = "upper")
public class UpperAdapter extends AAdapter<Message<String>> {

@Autowired
IUpperStringConversation gw;

它正在工作。问题是,如果我尝试使用其他项目(B.jar)中的 UpperAdapter。b-context.xml:

<import resource="classpath*:/*si-context.xml" />
<context:annotation-config />
<int:annotation-config />


@Component(value="router")
public class Router {

@Autowired
private Map<String, AAdapter<?>> adapters;

我在这里得到:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'upper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.company.proj.gw.IUpperStringConversation com.company.proj.adapter.UpperAdapter.gw; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.company.proj.gw.IUpperStringConversation] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

将 spring 日志级别设置为调试后,获取以下信息:

DEBUG o.s.c.a.ClassPathBeanDefinitionScanner - Ignored because not a concrete top-level class: URL [jar:file:/home/tomto/Documents/workspace-sts/integration-fw/src/main/resources/META-INF/lib/integration-fw-module-string-0.0.1-SNAPSHOT.jar!/com/company/proj/gw/IUpperStringConversation.class]

当然,这是真的,因为(也许我错了;))它将在运行时由 spring 生成网关。

IUpperStringConversation:

public interface IUpperStringConversation {
public String toUpperCase(String text);
}

我错过了什么?

谢谢!

最佳答案

我们遇到了类似的问题,我们的网关没有被注入(inject)到我们的服务对象中:

Project structure:
----------------
-parent/
-common/
--gateways defined here
-module-a/
-module-b/

模块-b 中收到的异常消息是:

org.springframework.beans.factory.BeanCreationException: ... Injection of autowired dependencies failed
...
IllegalArgumentException: Class must not be null

显然这个问题是由我们对 module-b 类路径的依赖冲突引起的。在我们清理了 pom.xml 中的 Spring 依赖项之后,它就起作用了!

关于java - Spring 集成: gateway bean not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16559515/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com