2014-02-14 21 views
0

我第一次使用Spring動態模塊。我試圖通過一個包暴露一個服務(簡單listofValuesDAO Bean),並試圖將它注入到另一個包中以使用該bean。 下面是Bundle1的OSGi的context.xml的配置標籤通過服務暴露:導出的服務不在我的包中注入Spring動態模塊

<osgi:service ref="listOfValuesDAO" auto-export="interfaces"/> 

,我想它在bundle2中通過下面的標籤在OSGi的context.xml中獲取:

<osgi:reference id="listOfValuesDAO" interface="com.dao.IListOfValuesDAO" /> 

的問題是,當我嘗試使用下面的配置來注入它在我的豆在bundle2中:

<bean id="exportServiceImpl" class="com.service.impl.ExportServiceImpl"> 
    <property name="listOfValuesDAO" ref="listOfValuesDAO"/> 
</bean> 

系統拋出異常如下:

Exception in thread "SpringOsgiExtenderThread-85"org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exportServiceImpl' defined in URL [bundle://325.16:0/META-INF/spring/module-context.xml]: 

Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'listOfValuesDAO' of bean class [com.service.impl.ExportServiceImpl]: 

Bean property 'listOfValuesDAO' is not writable or has an invalid setter method. Did you mean 'listOfValuesDao'? 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 

下面是財產在我ExportServiceImpl類:

public class ExportServiceImpl implements IExportService { 
IListOfValuesDAO listOfValuesDao; 
public void setListOfValuesDao(IListOfValuesDAO listOfValuesDao) { 
    this.listOfValuesDao = listOfValuesDao; 
} 
public IListOfValuesDAO getListOfValuesDao() { 
    return listOfValuesDao; 
} 
} 

可能有人請幫我解決這個問題呢?

回答

2

這似乎是一個案件不一致的問題:listOfValuesDaolistOfValuesDAO是不同的名稱。

您使用Service中的第一個版本,並使用XML bean定義中的第二個版本。嘗試:

<bean id="exportServiceImpl" class="com.service.impl.ExportServiceImpl"> 
    <property name="listOfValuesDao" ref="listOfValuesDao"/> 
</bean> 
+0

謝謝大衛,這是我的一個愚蠢的錯誤。它的工作現在。再次感謝。 –