2

I want to create a list of beans with an ID so that I can use ApplicationContext.getBean() to retrieve it into my standalone application.

I created the list this way:

<list id="airMessageHandlers">
    <bean id="signInResultHandler" class="com.blah.AirMessageHandler"/>
</list>

Then I want to do

getBean("airMessageHandlers");

The problem is that when I bring in the XML file, I get:

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)

... Caused by: 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 com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) at 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) ...

I couldn't find an example of a list as a stand alone bean and I'm wondering if that is a problem, but the DTD looks fine for this.

3

1 Answer 1

1

Turns out the solution was:

<util:list id="airMessageHandlers">
    <ref bean="signInResultHandler"/>
</util:list>

<bean id="signInResultHandler" class="com.blah.AirMessageHandler"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.