我第一次使用 Spring 动态模块。我试图通过一个包公开一个服务(简单的listofValuesDAO Bean),并试图将它注入另一个包以使用该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;
}
}
有人可以帮我解决这个问题吗?