Dave
Dave

Reputation: 21924

Create Spring Bean where class is a string?

Is there some kind of bean factory or static class that I can use within a Spring configuration file to create an instance of a Java class and set its properties? Something like this:

<bean id="myThingy" class="org.whatever.specialBeanMaker">
     <property class="${maven.filtered.property.value}" />
     <properties>
        <property name="a" value="...." />
        <property name="b" value="...." />
        <property name="c" value="...." />
     </properties>
</bean>

In other words, I need to make a bean from a class I won't know until runtime (because of filtering, JNDI, propertyPlaceholderConfigurer, etc.

Upvotes: 1

Views: 910

Answers (1)

Ryan Stewart
Ryan Stewart

Reputation: 128849

No need for anything special. Just do it like you'd expect:

<bean class="${whateverClass}"/>

Upvotes: 2

Related Questions