我有一个有趣的问题。
当我启动 glassfish 服务器时,一切正常。但是,我更改了一些代码并发布了服务器,然后运行我的客户端(SistemGirisClientKullaniciDogrula
)。应用程序抛出此异常:
java.lang.ClassCastException: tr.com.app.Kullanici cannot be cast to tr.com.app.Kullanici.
有趣的是,Glassfish 服务器重新启动后,应用程序工作正常。
我正在使用restlet-spring-hibernate。我还使用 JAXB (org.restlet.ext.jaxb.jar) 将 XML 转换为 Java 对象。我的应用服务器是Glassfish v3.0
配置详细信息
- 休息2.0.5
- 春天3.0.5
- 休眠3.3.2
- 玻璃鱼 v3.0
客户端类(仅供测试)
import java.io.IOException;
import org.restlet.Client;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.MediaType;
import org.restlet.data.Method;
import org.restlet.data.Protocol;
import org.restlet.ext.jaxb.JaxbRepresentation;
public class SistemGirisClientKullaniciDogrula {
public static void main(String[] Args) throws IOException {
String url = "http://localhost:8080/Project/sistemgirisws";
Client client = new Client(Protocol.HTTP);
Kullanici kullanici = new Kullanici();
kullanici.setKodu("1");
JaxbRepresentation<Kullanici> jaxbRepresentationSendingKullanici= new JaxbRepresentation<Kullanici>(MediaType.APPLICATION_XML, kullanici);
Request request = new Request(Method.GET, url, jaxbRepresentationSendingKullanici);
Response response = client.handle(request);
JaxbRepresentation<Kullanici> kullaniciResponse = new JaxbRepresentation<Kullanici>(response.getEntity(), Kullanici.class);
kullanici = kullaniciResponse.getObject();
System.out.println("kullanici id : " + kullanici.getId());
}
}
网络服务
public class ProjectWebService {
/**
*
* @param representation
* @return
*/
@Get
public Representation getKullanici(Representation representation) {
JaxbRepresentation<Kullanici> jaxbRepresentation = new JaxbRepresentation<Kullanici>(representation, Kullanici.class);
Kullanici kullanici = new Kullanici();
try {
kullanici = jaxbRepresentation.getObject(); //THIS LINE THROW java.lang.classCastException tr.com.app.Kullanici cannot be cast to tr.com.app.Kullanici.
} catch (IOException e) {
e.printStackTrace();
}
try {
kullanici = sistemGirisBusinessManager.kullaniciDogrula(kullanici);
getResponse().setStatus(Status.SUCCESS_OK);
return new JaxbRepresentation<Kullanici>(MediaType.APPLICATION_XML, kullanici);
} catch (Exception exception) {
exception.printStackTrace();
getResponse().setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
return new JaxbRepresentation<MesajList>(MediaType.APPLICATION_XML, sistemGirisBusinessManager.getMesajList());
}
}
}
有谁知道问题是什么?