Java Mailing List Archive

http://www.junlu.com/

Home » user.castor »

Re: [castor-user] Question about Spring FactoryBeans for Castor XML

Akihito Nakamura

2010-02-16

Replies: Find Java Web Hosting

Author LoginPost Reply
> In your Castor 1.3.1 and Spring combination does your spring xml context
> file have a bean like the following?
>
> <bean id="xmlContext" class="org.castor.spring.xml.XMLContextFactoryBean" />

No. My Spring beans are defined like:
========
  <bean id="aMarshaller"
    class="org.springframework.oxm.castor.CastorMarshaller">
    <property name="mappingLocations"
          value="classpath:castor-xml-mapping.xml"/>
    <property name="ignoreExtraAttributes" value="true"/>
    <property name="ignoreExtraElements"  value="true"/>
  </bean>
========
This is almost same as the one in the article.


> If so where should XMLContextFactoryBean come from?

With Spring 3.0.0, we don't need XMLContextFactoryBean.
The Spring JARs, including org.springframework.oxm-3.0.0.RELEASE.jar,
and the Castor JARs are requied.

Here, the CastorMarshaller's methods are different from
Castor's Marshaller class, but easy to change to.
The API of org.springframework.oxm.castor.CastorMarshaller
is found in the Spring javadoc.


With Spring 2.5.x, we need the SNAPSHOT JAR or SVN source
of Castor XML Spring factory beans, including XMLContextFactoryBean.
And the Spring context looks like:
========
  <bean id="aXmlContext"
    class="org.castor.spring.xml.XMLContextFactoryBean">
    <property name="mappingLocations">
       <list>
          <value>six-oval_castor-xml-mapping.xml</value>
       </list>
    </property>
    <property name="castorProperties">
       <props>
          <prop key="org.exolab.castor.xml.strictelements">false</prop>
       </props>
    </property>
  </bean>

  <bean id="aMarshaller"
    class="org.castor.spring.xml.CastorMarshallerFactoryBean">
    <property name="xmlContext">
       <ref local="aXmlContext"/>
    </property>
  </bean>

  <bean id="aUnmarshaller"
    class="org.castor.spring.xml.CastorUnmarshallerFactoryBean">
    <property name="xmlContext">
       <ref local="aXmlContext"/>
    </property>
    <property name="ignoreExtraElements"><value>true</value></property>
    <property name="ignoreExtraAttributes"><value>true</value></property>
  </bean>
========
Here, aMarshaller's type is Castor's Marshaller class.



> On Tue, Feb 16, 2010 at 9:11 PM, Akihito Nakamura <
> nakamura-akihito@(protected):
>
> > The following article is a good introduction.
> >
> > Meet the Object/XML mapping support in Spring
> > http://www.ibm.com/developerworks/xml/library/x-springXOM/
> >
> >
> > Castor 1.3.1, in combination with Spring 3.0.0, works successfully.
> >
> >
> > >*Subject: [castor-user] Question about Spring FactoryBeans for Castor XML
> > >*From: Zachariah Young <zpyoung@(protected)>
> > >*Date: Tue, 16 Feb 2010 20:54:08 -0600
> > >
> > > I'm trying to wire up Castor with Spring. I have read
> > > http://www.castor.org/spring-xml-intro.html but I'm getting and error
> > when I
> > > run my app. I'm getting the following error.
> > >
> > > Cannot find class [org.castor.spring.xml.XMLContextFactoryBean]
> > >
> > > I have tried both Java 1.5 and 1.6. and Spring 2.5.6 and Spring 3. I'm
> > > trying to use Castor 1.3.1
> > >
> > > I found the snapshot for Spring-xml and tried that but the package name
> > was
> > > not the same.
> > >
> > http://snapshots.repository.codehaus.org/org/codehaus/castor/spring-xml/1.0-SNAPSHOT/
> > >
> > > Then I found this little gem by doing a google search
> > > http://www.jarfinder.com/index.php/jars/versionInfo/56486 But I'm not
> > able
> > > to find a 1.3.1 version.
> > >
> > > Since the documentation does not state that I should include an
> > additional
> > > jar file I just assumed that I was in one of the core jar files.
> > >
> > >
> > > Also in my search I have discovered that Spring has Castor so should I be
> > > using that instead.
> > >
> > > If someone could post a good blog post on how to set this up that would
> > be
> > > GREAT!!!!
> > >
> > >
> > >
> > > --
> > > Zachariah Young
> > > http://zachariahyoung.com
> >
> >
> > ----
> > Akihito NAKAMURA @ AIST
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list, please visit:
> >
> >   http://xircles.codehaus.org/manage_email
> >
> >
> >
>
>
> --
> Zachariah Young
> President of NW Arkansas .Net User Group
> Co-Founder of Virtual ALT.NET
> INETA VUG Mentor
> http://zachariahyoung.com
> zpyoung@(protected)
> (479) 966-9169


----
Akihito NAKAMURA
National Institute of
  Advanced Industrial Science and Technology (AIST)
Information Technology Research Institute


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 junlu.com - Jax Systems, LLC, U.S.A.