Reputation: 17
I want to create a spring bean as below.
<bean id="qNameString" class="javax.xml.xpath.XPathConstants.STRING"/>
Here I want the reference to return type which is a QName but I understand the way I referred is wrong. Can someone please help on this.
Upvotes: 0
Views: 185
Reputation: 57767
Spring can create a QName for you like this:
<bean id="qName" class="java.xml.namespace.QName">
<constructor index="0" value="localpart"/>
<constructor index="1" value="namespaceURI"/>
</bean>
Replace localpart
and namespaceURI
with the local name and namespace.
To reference a constant in a class, like javax.xml.xpath.XPathConstants.STRING
<bean id="qNameString" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="targetField" value="javax.xml.xpath.XPathConstants.STRING"/>
</bean>
A shorter version is available with the util
schema:
<util:constant static-field="java.xml.xpath.XPathConstants.STRING"/>
Apart from being shorter, the id
of the bean will be java.xml.xpath.XPathConstants.STRING
rather than qNameString
.
See FieldRetrievingFactoryBean and The util schema
Upvotes: 0
Reputation: 403581
That won't work, because class="javax.xml.xpath.XPathConstants.STRING"
makes no sense, since what you're referring to isn't a class.
You can refer to static fields using <util:constant>
, as documented here:
<property name="...">
<util:constant static-field="javax.xml.xpath.XPathConstants.STRING"/>
</property>
Upvotes: 1