Spring BeanIsAbstractException
I am trying to load spring beans using XmlWebApplicationContext's setConfigLocations method. However, I keep getting
BeanIsAbstractException
I know the bean is abstract, I configured it this way, so spring needs to know that it is not trying to create it.
I am using Spring2.0.8.jar with jetspeed2.1.
Spring bean:
<bean id="ThreadPool" abstract="true" class="com.sample.ThreadPoolFactoryBean"/>
code:
ctx = appContext; appContext.refresh(); BeanFactory factory = appContext.getBeanFactory(); String[] beansName = appContext.getBeanFactory() .getBeanDefinitionNames(); ... map.put(beansName[mnCnt], factory.getBean(beansName[mnCnt]));
Does anyone have any idea?
source to share
The following code will try and fail to instantiate your abstract class:
map.put(beansName[mnCnt], factory.getBean(beansName[mnCnt]));
There is simply no confusion, "abstract" beans are not the same as abstract classes. They are primarily a convenient mechanism for reducing the parameters of repeated properties.
The child bean definition inherits the values ββof the constructor argument, property values ββand method are overridden from the parent, with the option to add new values. If init method, destroy method, factory bean and / or factory, they will override their respective parent settings.
Contrived example:
class Fruit {
private String colour;
private String name;
// setters...
}
class Car {
private String colour;
private String manufacturer;
// setters...
}
and
<!-- specifying a class for an abstract bean is optional -->
<bean id="sharedPropsBean" abstract="true">
<property name="colour" value="red" />
</bean>
<bean id="myFruit" parent="sharedPropsBean" class="Fruit">
<property name="name" value="apple" />
</bean>
<bean id="myCar" parent="sharedPropsBean" class="Car">
<property name="manufacturer" value="Ferrari" />
</bean>
source to share
Spring bean:
<bean id="ThreadPool" abstract="true" class="com.sample.ThreadPoolFactoryBean"/>
code:
ctx = appContext; appContext.refresh(); BeanFactory factory = appContext.getBeanFactory(); String[] beansName = appContext.getBeanFactory() .getBeanDefinitionNames();
Then when I iterate over the array of strings it gives an exception.
source to share