导出的服务没有在Spring Dynamic Modules中注入我的包中

时间:2014-02-14 09:19:14

标签: spring osgi osgi-bundle spring-dm dosgi

我第一次使用Spring Dynamic Modules。我试图通过一个bundle公开一个服务(简单的listofValuesDAO Bean),并试图将它注入另一个bundle来使用bean。 下面是Bundle1的osgi-context.xml中的配置标记,通过该标记公开了服务:

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

我试图通过osgi-context.xml中的下面标记在Bundle2中获取它:

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

问题在于,当我尝试使用以下配置将它注入Bundle2中的bean:

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

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

似乎是案件不一致的问题:listOfValuesDaolistOfValuesDAO是不同的名称。

您使用Service中的第一个版本,以及XML bean定义中的第二个版本。尝试:

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