Question

I am using Spring Dynamic Modules for the first time. I have tried to expose a service (simple listofValuesDAO Bean) through a bundle and am trying to inject it in another bundle to use the bean. Below is configuration tag in osgi-context.xml of Bundle1 through which service was exposed:

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

and I am trying to fetch it in Bundle2 through below tag in osgi-context.xml:

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

The issue is that when I try to inject it in my bean in Bundle2 using below configuration:

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

System throws below exception:

 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)

Below is property in my ExportServiceImpl Class:

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

Could someone please help me in resolving this issue?

Was it helpful?

Solution

It seems to be a problem with case inconsistency: listOfValuesDao and listOfValuesDAO are different names.

You use the first version in the Service, and the second in the XML bean definition. Try:

<bean id="exportServiceImpl" class="com.service.impl.ExportServiceImpl">
    <property name="listOfValuesDao" ref="listOfValuesDao"/>
</bean>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top