I have class like below :
class Foo<KeyType, ValueType> {
private Producer<KeyType, ValueType> kafkaProducer;
public Foo() {
this.kafkaProducer = new Producer<KeyType, ValueType>(new ProducerConfig());
}
}
There is another DAO class which uses this Foo class which looks like below :
class CompanyDao {
@Autowired
private Foo<String, Integer> fooHelper;
}
I want Spring to inject object of type Foo
in fooHelpder
object. For this I am using following XML configuration :
<bean id="fooHelper" class="com.ask.util.Foo">
<property name="KeyType" value="java.lang.String" />
<property name="ValueType" value="Integer" />
</bean>
<bean id="CompanyDao" class="com.ask.dao.CompanyDao">
<property name="fooHelper"><ref bean="fooHelder"/></property>
</bean>
When I use this XML configurtion, Spring throws following error :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fooHelper' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'KeyType' of bean class [com.ask.util.fooHelper]: Bean property 'KeyType' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
Any idea how to resolve this error?