Announcement Announcement Module
Collapse
No announcement yet.
Castor Mapping Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Castor Mapping

    Hi, im trying to use Spring Castor marshalling:
    In my spring-context.xml i have :
    Code:
    <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" >
            <property name="mappingLocation" value="mapping.xml" />
     </bean>
    in my castor mapping file (mapping.xml) i have
    Code:
    <!DOCTYPE databases PUBLIC
      "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
      "http://castor.exolab.org/mapping.dtd">
    <mapping>
    	<description>
    		My mapping file
    	</description>
    	<class
    		name="mapping.object.Ticket">
    		<mapp-to xml="Ticket" />   
    		<field name="name">
    			<bind-xml name="nom" />
    		</field>
    		<field name="event">
    			<bind-xml name="input-event" />
    		</field>
    	</class>
    </mapping>
    in my main :
    Code:
    ApplicationContext ap = new ClassPathXmlApplicationContext("spring-context.xml");
    CastorMarshaller marshaller = (CastorMarshaller) ap.getBean("castorMarshaller");
    marshaller.marshal(myObject, new StreamResult(os));
    What makes this massage here?
    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'castorMarshaller' defined in class path resource [spring-context.xml]: Invocation of init method failed; nested exception is org.springframework.oxm.castor.CastorSystemException: Could not load Castor mapping: Could not find the class ; nested exception is org.exolab.castor.mapping.MappingException: Could not find the class 
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1362)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:413)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:735)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
    	at mapping.test.MyFirstMapping.main(MyFirstMapping.java:38)
    Caused by: org.springframework.oxm.castor.CastorSystemException: Could not load Castor mapping: Could not find the class ; nested exception is org.exolab.castor.mapping.MappingException: Could not find the class 
    	at org.springframework.oxm.castor.CastorMarshaller.afterPropertiesSet(CastorMarshaller.java:224)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1390)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1359)
    	... 14 more
    Caused by: org.exolab.castor.mapping.MappingException: Could not find the class 
    	at org.exolab.castor.mapping.loader.AbstractMappingLoader.resolveType(AbstractMappingLoader.java:379)
    	at org.exolab.castor.mapping.loader.AbstractMappingLoader.createFieldDesc(AbstractMappingLoader.java:498)
    	at org.exolab.castor.xml.XMLMappingLoader.createFieldDesc(XMLMappingLoader.java:461)
    	at org.exolab.castor.mapping.loader.AbstractMappingLoader.createFieldDescriptors(AbstractMappingLoader.java:408)
    	at org.exolab.castor.xml.XMLMappingLoader.createClassDescriptor(XMLMappingLoader.java:231)
    	at org.exolab.castor.mapping.loader.AbstractMappingLoader.createClassDescriptors(AbstractMappingLoader.java:268)
    	at org.exolab.castor.xml.XMLMappingLoader.loadMapping(XMLMappingLoader.java:152)
    	at org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:164)
    	at org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:130)
    	at org.exolab.castor.xml.XMLContext.addMapping(XMLContext.java:82)
    	at org.springframework.oxm.castor.CastorMarshaller.createXMLContext(CastorMarshaller.java:254)
    	at org.springframework.oxm.castor.CastorMarshaller.afterPropertiesSet(CastorMarshaller.java:221)
    Think you v.M

  • #2
    I don't know why you get that specific error, but you should ensure that your mapping file validates against the Castor DTD. One obvious error is "mapp-to", which should be "map-to".

    Comment


    • #3
      Check this out this article have tutorial for castor mapping :
      http://springkbase.blogspot.com/2009...th-castor.html

      Comment


      • #4
        Try using "targetClass" property. Something like this:

        Code:
        <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
            <property name="targetClass" value="foo.bar.Request"/>
        </bean>
        <bean id="castorUnmarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
            <property name="targetClass" value="foo.bar.Response"/>
        </bean>

        Comment

        Working...
        X