Hi
I'm trying to create my own namespace for use in Spring.
The XSD contains an element with two properties and includes the identifiedType type defined by Spring.
I've created a NamespaceHandler and a BeanDefinitionParser, and all works fine...
until I enter a second element in the Spring context of the same type.
I then get a "no unique bean of type ..." exception.
Does anyone have a hint as to what I might be missing?
A snippet of the XSD:
A snippet of the BeanDefinitionParser:Code:<xsd:element name="carrier"> <xsd:complexType> <xsd:complexContent> <xsd:extension base="bean:identifiedType"> <xsd:sequence> <xsd:element name="factory"> <xsd:complexType> <xsd:attribute name="jndi" type="xsd:string" /> <xsd:attribute name="ref" type="xsd:string" /> </xsd:complexType> </xsd:element> <xsd:element name="destination"> <xsd:complexType> <xsd:attribute name="jndi" type="xsd:string" /> <xsd:attribute name="ref" type="xsd:string" /> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> </xsd:element>
Snippet of Spring config:Code:public class JMSCarrierBeanDefinitionParser extends AbstractBeanDefinitionParser { public static final String FACTORY = "factory"; public static final String DESTINATION = "destination"; public static final String JNDI = "jndi"; public static final String REF = "ref"; @Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext context) { BeanDefinitionBuilder root = BeanDefinitionBuilder.genericBeanDefinition(JMSCarrier.class); add(DomUtils.getChildElementByTagName(element, FACTORY), root); add(DomUtils.getChildElementByTagName(element, DESTINATION), root); return root.getBeanDefinition(); } private void add(Element element, BeanDefinitionBuilder root) { final String jndi = element.getAttribute(JNDI); final String ref = element.getAttribute(REF); final boolean hasJNDI = (jndi != null) && (jndi.length() > 0); final boolean hasREF = (ref != null) && (ref.length() > 0); if (hasJNDI) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(JndiObjectFactoryBean.class); builder.addPropertyValue("jndiName", jndi); root.addConstructorArgValue(builder.getBeanDefinition()); } else if (hasREF) { root.addConstructorArgReference(ref); } } }
Code:<jms:carrier id="primary"> <jms:factory jndi="some/address" /> <jms:destination jndi="some/other/address" /> </jms:carrier>


Reply With Quote