2013-05-15 83 views
1

我嘗試在不同的罐子中使用彈簧集成。 在a.jar文件的SI-context.xml中:彈簧集成:未找到網關bean

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

後,我設置的彈簧日誌級別來調試,得到這樣的信息:

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] 

當然,這是真的,因爲(也許我錯了;))它將在春天在運行時生成的網關。

的IUpperStringConversation:

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

我錯過了什麼?

Thx!

+0

爲'org.springframework'開啓DEBUG日誌記錄;你會得到豐富的調試日誌xml解析,bean發現/創建等。 –

+0

你有沒有解決過這個問題? – EoD

回答

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 

顯然,問題正在由對模塊-b類路徑的衝突依賴造成。在我們清理了pom.xml中的Spring依賴關係後,它工作了!