SpringとCastorのO/Xマッパーについて知識のある方助けてください。


下記のサイトでSpringとCastorでO/Xマッパーについて勉強しました。

* http://www.ibm.com/developerworks/jp/xml/library/x-springXOM/

しかし、上記のサイトのソースをダウンロードし、足りないjarを揃えてやってみましたが、
エラーが出てきてなかなかうまく動くことができませんでした。

* 揃えたファイルの一式は下記の所でダウンロードできます。
http://dl.dropbox.com/u/25436822/Spring_Castor/OXMTest.zip

* 自分が色々試して見た結果、下記のxmlファイルの
```<property name="mappingLocation" value="classpath:mapping.xml" />```
の部分のmapping.xmlファイルがオブジェクト生成時にパスの指定の問題でPGが探せなかったことと考えています。ここまで見てもし何か分かったら、教えてください。ちなみに、絶対パスで設定してみたこともあります。
 ```<property name="mappingLocation" value="C:\\workspace\\OXMTest\\bin\\mapping.xml" />```

   	
 
```xml:\workspace\OXMTest\config\applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="oxmExample" class="com.xyz.OXMExample">
        <property name="marshaller" ref="castorMarshaller" />
        <property name="unmarshaller" ref="castorMarshaller" />
    </bean>
    <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
       <!--- ※ここの指定が正しくないのか？？PGがmapping.xmlを読めないです。※ --->
    	<property name="mappingLocation" value="classpath:mapping.xml" />
    </bean>
</beans>
```

* 理由：```<property name="mappingLocation" value="classpath:mapping.xml" />```
の部分をコメントアウト前に下記のエラーが表示され、それをコメントアウトするとその次のエラーが表示されます。

```txt:①コメントアウト前のエラーメッセージ
log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oxmExample' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'castorMarshaller' while setting bean property 'marshaller'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'castorMarshaller' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/stream/XMLEventWriter
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:315)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1298)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1060)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:528)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:716)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:383)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
	at com.xyz.OXMExample.main(OXMExample.java:54)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'castorMarshaller' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/stream/XMLEventWriter
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:309)
	... 15 more
Caused by: java.lang.NoClassDefFoundError: javax/xml/stream/XMLEventWriter
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2395)
	at java.lang.Class.getDeclaredMethods(Class.java:1763)
	at java.beans.Introspector$1.run(Introspector.java:1265)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1263)
	at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1129)
	at java.beans.Introspector.getBeanInfo(Introspector.java:387)
	at java.beans.Introspector.getBeanInfo(Introspector.java:159)
	at java.beans.Introspector.getBeanInfo(Introspector.java:220)
	at java.beans.Introspector.<init>(Introspector.java:368)
	at java.beans.Introspector.getBeanInfo(Introspector.java:159)
	at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:222)
	at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:143)
	at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:269)
	at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptorInternal(BeanWrapperImpl.java:299)
	at org.springframework.beans.BeanWrapperImpl.isWritableProperty(BeanWrapperImpl.java:351)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1300)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1060)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
	... 21 more

```


```txt:②コメントアウト後のエラーメッセージ
log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamReader
	at org.springframework.oxm.support.AbstractMarshaller.marshal(AbstractMarshaller.java:95)
	at com.xyz.OXMExample.saveSimpleBean(OXMExample.java:33)
	at com.xyz.OXMExample.go(OXMExample.java:62)
	at com.xyz.OXMExample.main(OXMExample.java:56)
```

###実施環境はWindowsXPでした。

###実行当時のclasspathファイルの設定内容
```:.classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path="src"/>
	<classpathentry excluding="**/*.java" kind="src" path="config"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/org.springframework.oxm-3.0.0.M4.jar"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/castor-1.3.jar"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/castor-1.3-core.jar"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/castor-1.3-xml.jar"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/commons-logging-1.1.1.jar"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/log4j-1.2.15.jar"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/org.springframework.asm-3.0.0.M4.jar"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/org.springframework.beans-3.0.0.M4.jar"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/org.springframework.context-3.0.0.M4.jar"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/org.springframework.core-3.0.0.M4.jar"/>
	<classpathentry kind="lib" path="C:/workspace/OXMTest/lib/org.springframework.expression-3.0.0.M4.jar"/>
	<classpathentry kind="output" path="bin"/>
</classpath>


```

###http://dl.dropbox.com/u/25436822/Spring_Castor/OXMTest.zipのなかのソース抜粋。

```java:\workspace\OXMTest\src\com\xyz\OXMExample.java
package com.xyz;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;

public class OXMExample {
    private static final String FILE_NAME = "simplebean.xml";
    private SimpleBean simpleBean;
    
    private Marshaller marshaller;
    private Unmarshaller unmarshaller;

    public void setMarshaller(Marshaller marshaller) {
        this.marshaller = marshaller;
    }

    public void setUnmarshaller(Unmarshaller unmarshaller) {
        this.unmarshaller = unmarshaller;
    }

    public void saveSimpleBean() throws IOException {
        FileOutputStream os = null;
        try {
            os = new FileOutputStream(FILE_NAME);
            this.marshaller.marshal(simpleBean, new StreamResult(os));
        } finally {
            if (os != null) {
                os.close();
            }
        }
    }

    public void loadSimpleBean() throws IOException {
        FileInputStream is = null;
        try {
            is = new FileInputStream(FILE_NAME);
            this.simpleBean = (SimpleBean) this.unmarshaller.unmarshal(new StreamSource(is));
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }

    public static void main(String[] args) throws IOException {
        ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        OXMExample ex = (OXMExample) appContext.getBean("oxmExample");
        ex.go();
    }
    
    private void go() throws IOException {
    	simpleBean = getSimpleBean();
    	
        saveSimpleBean();
        loadSimpleBean();
        
        System.out.println("name: " + simpleBean.getName());
        System.out.println("job descritpion: " + simpleBean.getJobDescription());
        System.out.println("age: " + simpleBean.getAge());
        System.out.println("executive: " + simpleBean.isExecutive());
        
    }
    
    
    private SimpleBean getSimpleBean() {
    	SimpleBean simpleBean = new SimpleBean();
    	simpleBean.setAge(35);
    	simpleBean.setExecutive(false);
    	simpleBean.setJobDescription("Janitor");
    	simpleBean.setName("Mister Jones");
    	
    	return simpleBean;
    	
    }
}
```

```java:\workspace\OXMTest\src\com\xyz\SimpleBean.java
package com.xyz;

public class SimpleBean {

	private String name;
	private Integer age;
	private String jobDescription;
	private boolean executive;
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}
	public String getJobDescription() {
		return jobDescription;
	}
	public void setJobDescription(String jobDescription) {
		this.jobDescription = jobDescription;
	}
	public boolean isExecutive() {
		return executive;
	}
	public void setExecutive(boolean executive) {
		this.executive = executive;
	}
	
	
}

```

```xml:\workspace\OXMTest\config\applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="oxmExample" class="com.xyz.OXMExample">
        <property name="marshaller" ref="castorMarshaller" />
        <property name="unmarshaller" ref="castorMarshaller" />
    </bean>
    <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
    	<property name="mappingLocation" value="classpath:mapping.xml" />
    </bean>
</beans>
```

```xml:\workspace\OXMTest\config\mapping.xml
<?xml version="1.0"?>

<mapping>
	<class name="com.xyz.SimpleBean">
	           
	   <map-to xml="simplebean"/>
	
	   <field name="age" type="integer">
	      <bind-xml name="age" node="element"/>
	   </field>
	   
	   <field name="executive" type="boolean">
	      <bind-xml name="is-executive" node="element"/>
	   </field>
	   
	   <field name="jobDescription" type="string">
	      <bind-xml name="job" node="element"/>
	   </field>
	
	   <field name="name" type="string">
	      <bind-xml name="name" node="element"/>
	   </field>
	</class>
</mapping>
```

```xml:\workspace\OXMTest\settings
<?xml version="1.0" encoding="UTF-8"?>
<settings>
	<fooEnabled>false</fooEnabled>
</settings>
```