在类是字符串的地方创建Spring Bean? [英] Create Spring Bean where class is a string?
本文介绍了在类是字符串的地方创建Spring Bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Spring配置文件中是否可以使用某种bean工厂或静态类来创建Java类的实例并设置其属性?像这样:
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>
换句话说,我需要使用直到运行时才知道的类来制作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.
推荐答案
不需要任何特殊的东西,就像您期望的那样:
No need for anything special. Just do it like you'd expect:
<bean class="${whateverClass}"/>
这篇关于在类是字符串的地方创建Spring Bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文