使用静态变量命名Spring Bean

时间:2015-05-25 04:09:13

标签: java spring

我试图像这样命名一个bean:

<bean id="${EntityManager.ALGO}" class="path.AlgoManagerImpl">
        <property name="dao" ref="algoDao" />
</bean>

其中:

public interface EntityManager<T> {

    /** */
    public static final String ALGO = "algoManager654321";

所以我可以像豆一样得到:

EntityManager<Algo> algoMngr = (EntityManager<Algo>) appContext
                    .getBean(EntityManager.ALGO);

但我明白了:

Offending resource: class path resource ; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 7 in XML document from class path resource is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 101; cvc-datatype-valid.1.2.1: '${EntityManager.ALGO}' is not a valid value for 'NCName'.
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location

...

Caused by: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 101; cvc-datatype-valid.1.2.1: '${EntityManager.ALGO}' is not a valid value for 'NCName'.

如何指定静态字符串来命名该资源,而不是在任何地方复制/粘贴该特定名称?它甚至可以吗?

0 个答案:

没有答案