spring BeanIsAbstractException

im trying to load spring beans using XmlWebApplicationContext setConfigLocations method however i keep getting a

BeanIsAbstractException

I know that the bean is abstract, i have it configured this way, so Spring should know not to try instantiate

im 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]));

Anyone any ideas.

Answers


map.put(beansName[mnCnt], factory.getBean(beansName[mnCnt]));

There's your problem, isn't it? By calling getBean with the name of the abstract bean, you try to instantiate it, which will generate an exception.


The following code will try, and fail to create an instance of your abstract class:

map.put(beansName[mnCnt], factory.getBean(beansName[mnCnt]));

Just so there is no confusion, 'abstract' beans are not the same as abstract classes.They are primarily a convenient mechanism for reducing duplicate property settings.

A child bean definition will inherit constructor argument values, property values and method overrides from the parent, with the option to add new values. If init method, destroy method, factory bean and/or factory method are specified, they will override the corresponding parent settings.

A 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>

Need Your Help

How to rename a file according his folder name via batch script

batch-file batch-processing ms-dos batch-rename

I have this part of batch script which is doing following: -There is a main folder, in the main folder are two files (movie &amp; subtitle file) and one Sub-folder called 'Subtitles' -This script ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.