1

I try to using spring integration in different jars. In the 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"/>

In a bean I'm using this gateway:

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

    @Autowired
    IUpperStringConversation gw;

It's working. The problem is, if I try to using my UpperAdapter from an other project (B.jar). 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;

And here I get:

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)}

After I set the spring log level to debug, get this information:

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]

Of course, it's true, becouse (maybe I'm wrong ;)) it would be at runtime generated gateway by spring.

The IUpperStringConversation:

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

What I missed?

Thx!

4

1 回答 1

0

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

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 依赖项后,它就起作用了!

于 2013-09-03T20:26:14.017 回答