wood burning stoves 2.0*
The moose likes Spring and the fly likes Problem with <util:map  - Invalid nested exception is org.xml.sax.SAXParseException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Problem with <util:map  - Invalid nested exception is org.xml.sax.SAXParseException" Watch "Problem with <util:map  - Invalid nested exception is org.xml.sax.SAXParseException" New topic
Author

Problem with <util:map - Invalid nested exception is org.xml.sax.SAXParseException

Mat Anthony
Ranch Hand

Joined: May 21, 2008
Posts: 232
Hi All,
for a detected device I would like to use an appropriate xsl file.
To do this I have created a DeviceDisplayDetector object I have attempted to inject in
deviceDisplayTypes so that I can get at the associated xsl for the device that has made a request.

The configuration code within my applicationContext.xml is as follows:-

<bean id="deviceDetector" class="my.DeviceDisplayDetector">
<property name="deviceDisplayTypes"><ref bean="deviceDisplayTypes"/></property>
</bean>

<!-- Setup PC specific attributes -->
<util:map id="deviceDisplayTypes" map-class="java.util.HashMap">
<property name="PC"><ref bean="pcDeviceAttrib"/></property>
<property name="MOBILE"><ref bean="mobileDeviceAttrib"/></property>
</util:map>

<util:map id="pcDeviceAttrib" map-class="java.util.HashMap">
<entry key="my.vo.FootBallImageVO" value="PC_FootBallImageVO.xsl"/>
<entry key="my.ce.TennisImageVO" value="PC_TennisImageVO.xsl"/>
</util:map>

<util:map id="mobileDeviceAttrib" map-class="java.util.HashMap">
<entry key="my.vo.FootBallImageVO" value="MOBILE_FootBallImageVO.xsl"/>
<entry key="my.ce.TennisImageVO" value="MOBILE_TennisImageVO.xsl"/>
</util:map>

I keep getting the following error:-
applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException:
<Line 96, Column 12>: XML-20148: (Error) Invalid element 'util:map' in content of 'beans', expected elements '[import, alias, bean]'.

Any ideas

Mat
Mat Anthony
Ranch Hand

Joined: May 21, 2008
Posts: 232
Can a bean ref a util:map as in my example, or can anybody suggest a better way.
Mat Anthony
Ranch Hand

Joined: May 21, 2008
Posts: 232
Can some kind person help me with this problem

Mat
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

What's the namespace definition of your beans XML look like? Have you defined the "util" namespace?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Mat Anthony
Ranch Hand

Joined: May 21, 2008
Posts: 232
Hi Nathan,
Thanks for the reply.

I just looked inside my applicationContext.xml and have noticed, that I just have the following defined:-

file:applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD//BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<bean id="deviceDetector" class="my.DeviceDisplayDetector">
<property name="deviceDisplayTypes"><ref bean="deviceDisplayTypes"/></property>
</bean>

<!-- Setup PC specific attributes -->
<util:map id="deviceDisplayTypes" map-class="java.util.HashMap">
<property name="PC"><ref bean="pcDeviceAttrib"/></property>
<property name="MOBILE"><ref bean="mobileDeviceAttrib"/></property>
</util:map>

<util:map id="pcDeviceAttrib" map-class="java.util.HashMap">
<entry key="my.vo.FootBallImageVO" value="PC_FootBallImageVO.xsl"/>
<entry key="my.ce.TennisImageVO" value="PC_TennisImageVO.xsl"/>
</util:map>

<util:map id="mobileDeviceAttrib" map-class="java.util.HashMap">
<entry key="my.vo.FootBallImageVO" value="MOBILE_FootBallImageVO.xsl"/>
<entry key="my.ce.TennisImageVO" value="MOBILE_TennisImageVO.xsl"/>
</util:map>

</beans>


Do I need to include the following as well :-

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">


Mat
Mat Anthony
Ranch Hand

Joined: May 21, 2008
Posts: 232
Hi Nathan,
thanks for the reply, I just added:-

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">

and it seems to work fine

Mat
 
jQuery in Action, 2nd edition
 
subject: Problem with <util:map - Invalid nested exception is org.xml.sax.SAXParseException
 
Similar Threads
BeanDefinitionStoreException
hibernate_springs
Spring Related-- @Autowired with Map<String, myObjectType> is not initialized in the IoC container
Spring IOC issues in MVC WebApplication with JSF integration
Beginning Spring: Syntax for Map<Integer, Double>?