Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring XML bean definition parser interprets <constructor-arg/> tags that are not in the beans namespace [SPR-7218] #11877

Closed
spring-projects-issues opened this issue May 19, 2010 · 7 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

nebhale opened SPR-7218 and commented

I've got a namespace which defines a slices:constructor-arg element (to be used in place of the beans:constructor-arg element). When running up an ApplicationContext I get the following error:

Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: <constructor-arg> element must specify a ref or value
Offending resource: '/Users/benhale/dev/workspaces/slices/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/slice-app/WEB-INF/lib/slice-2.jar': 'META-INF/slices/slice-context.xml'
Bean ''
	-> Constructor-arg
	at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:284)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parsePropertyValue(BeanDefinitionParserDelegate.java:938)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseConstructorArgElement(BeanDefinitionParserDelegate.java:800)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseConstructorArgElements(BeanDefinitionParserDelegate.java:684)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:481)

Simply changing the name of my tag to something other than constructor-arg resolves the issue. I've not tried with some of the other well known names (property comes to mind) but there might be issues there as well.


Affects: 3.0.2

Issue Links:

  • SLICE-100 Change the name of the ca tag to constructor-arg upon completion of SPR-7218 ("is depended on by")

Referenced from: commits 2676771, a6d9c90

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Ben, where is that parseBeanDefinitionElement call coming from - would be good to see the complete stacktrace there. We're only really calling that for the default namespace... Or is your namespace handler performing that call somewhere, in order to parse common bean definition attributes maybe?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

nebhale commented

Sorry about that. Just grab the subexception that seemed most pertinent. Here's all that I get:

Exception in thread "Slices-0" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unexpected failure during bean definition parsing
Offending resource: '/Users/benhale/dev/workspaces/slices/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/slice-app/WEB-INF/lib/slice-2.jar': 'META-INF/slices/slice-context.xml'
Bean ''; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: <constructor-arg> element must specify a ref or value
Offending resource: '/Users/benhale/dev/workspaces/slices/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/slice-app/WEB-INF/lib/slice-2.jar': 'META-INF/slices/slice-context.xml'
Bean ''
	-> Constructor-arg
	at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:291)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:497)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:396)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:365)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.processBeanDefinition(DefaultBeanDefinitionDocumentReader.java:259)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:154)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:133)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:93)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
	at org.springframework.context.support.GenericXmlApplicationContext.load(GenericXmlApplicationContext.java:84)
	at org.springframework.slices.internal.SpringApplicationSlice.start(SpringApplicationSlice.java:55)
	at org.springframework.slices.internal.StandardSlicesRuntime$1.run(StandardSlicesRuntime.java:52)
	at java.lang.Thread.run(Thread.java:637)
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: <constructor-arg> element must specify a ref or value
Offending resource: '/Users/benhale/dev/workspaces/slices/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/slice-app/WEB-INF/lib/slice-2.jar': 'META-INF/slices/slice-context.xml'
Bean ''
	-> Constructor-arg
	at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:284)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parsePropertyValue(BeanDefinitionParserDelegate.java:938)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseConstructorArgElement(BeanDefinitionParserDelegate.java:800)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseConstructorArgElements(BeanDefinitionParserDelegate.java:684)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:481)
	... 15 more

I'm using the NamespaceHandlerSupport class to register a BeanDefinitionDecorator (among other things) and in it, it never dispatches back to the Spring infrastructure.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Hmm, this is the regular call stack for a <bean> element in the default namespace... Could you debug why DefaultBeanDefinitionDocumentReader's parseBeanDefinitions thinks that your element lives in the default namespace? It basically parses your top-level element like it was a regular <bean> element - and <constructor-arg> just happens to be a well-known subelement there. A possible reason could be that the Element's namespaceURI is empty - maybe due to XML parser settings?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

nebhale commented

That might be the issue then. Basically I have something that looks like this:

<bean class="org.springframework.slices.samples.slice2.Bean">
    <slices:constructor-arg type="org.springframework.slices.samples.slice1.EchoService"/>
</bean>

Is it possible that the beans NamespaceHandler isn't dispatching the reading of the constructor arg element again?

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Yes, that's probably it. We're not checking for the namespace there at that level. So we'll simply have to restrict parsing to sub-elements which actually live in the default namespace themselves. Your slices:constructor-arg would then be picked up by a BeanDefinitionDecorator, I suppose (like when having a different name).

Juergen

@spring-projects-issues
Copy link
Collaborator Author

nebhale commented

Sounds good to me :) I'm not surprised this has never come up as there are very few use-cases to provide alternate declarations of the common tags.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Fixed through additional namespace checks at the element parsing level. Will be available in tonight's 3.0.3 snapshot. Would be great if you could give it a try tomorrow...

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants