我想创建一个带有ID的bean列表,以便我可以使用ApplicationContext.getBean()将其检索到我的独立应用程序中。
我用这种方式创建了列表:
<list id="airMessageHandlers">
<bean id="signInResultHandler" class="com.blah.AirMessageHandler"/>
</list>
然后我想做
的getBean( “airMessageHandlers”);
问题在于,当我引入XML文件时,我得到:
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 18 in XML document from class path resource [conf/portserver.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 37; cvc-complex-type.2.4.a: Invalid content was found starting with element 'list'. One of '{"http://www.springframework.org/schema/beans":import, "http://www.springframework.org/schema/beans":alias, "http://www.springframework.org/schema/beans":bean, WC[##other:"http://www.springframework.org/schema/beans"], "http://www.springframework.org/schema/beans":beans}' is expected.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
... 引起:org.xml.sax.SAXParseException; lineNumber:18; columnNumber:37; cvc-complex-type.2.4.a:从元素'list'开始发现无效内容。其中一个'{“http://www.springframework.org/schema/beans”:导入,“http://www.springframework.org/schema/beans”:别名,“http://www.springframework.org/schema/beans”:bean,WC [## other:“http://www.springframework.org/schema/beans”],“预计http://www.springframework.org/schema/beans“:beans}”。 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) 在com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325) ...
我找不到一个列表作为独立bean的例子,我想知道这是否有问题,但DTD看起来很好。
答案 0 :(得分:1)
原来解决方案是:
<util:list id="airMessageHandlers">
<ref bean="signInResultHandler"/>
</util:list>
<bean id="signInResultHandler" class="com.blah.AirMessageHandler"/>