サンプル
SampleWebMain.java
import javax.jws.WebMethod; import javax.jws.WebParam; //import javax.jws.WebService; import com.sample.entities.SampleEntity; //JAX-WSを使用する場合 //@WebService(serviceName = "SampleWebMainServiceWithJaxWs") public class SampleWebMain { @WebMethod public SampleEntity getSampleEntity( @WebParam(name = "name") String name) { return new SampleEntity(name); } }
SampleEntity.java
package com.sample.entities; import java.io.Serializable; //import javax.xml.bind.annotation.XmlRootElement; // 【1】JAX-WSを使用する場合、@XmlRootElement/@XmlElementが必要 //@XmlRootElement(name="SampleEntity") public class SampleEntity implements Serializable { private static final long serialVersionUID = 1L; private String name; // 【2】JAX-WSを使用する場合、デフォルト・コンストラクタが必要 public SampleEntity() { } // ★【重要】Getter/Setterが必要(public String nameだとAxis2では認識されない)★ public SampleEntity(String name) { this.name = name; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } }
出力結果
リクエスト<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sam="">http://sample.com"> <x:Header/> <x:Body> <sam:getSampleEntity> <sam:name>Ken</sam:name> </sam:getSampleEntity> </x:Body> </x:Envelope>レスポンス
<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="">http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header></soapenv:Header> <soapenv:Body> <ns:getSampleEntityResponse xmlns:ns="">http://sample.com"> <ns:return xmlns:ax21="http://entities.sample.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax21:SampleEntity"> <ax21:name>Ken</ax21:name> </ns:return> </ns:getSampleEntityResponse> </soapenv:Body> </soapenv:Envelope>
参考文献
http://stackoverflow.com/questions/3237473/jaxb-exception-class-not-known-to-this-contexthttp://stackoverflow.com/questions/14057932/javax-xml-bind-jaxbexception-class-nor-any-of-its-super-class-is-known-to-t
http://stackoverflow.com/questions/23510132/javax-xml-bind-marshalexception-nor-any-of-its-super-class-is-known-to-this-cont
http://stackoverflow.com/questions/18700196/javax-xml-bind-jaxbexception-class-classname-nor-any-of-its-super-class-is-kn
http://howtodoinjava.com/jaxb/solved-javax-xml-bind-jaxbexception-class-java-util-arraylist-nor-any-of-its-super-class-is-known-to-this-context/