我正在使用 Eclipse Juno IDE 和 Tomcat 7.0
我有一个服务器,在服务器内我有TaxiStation类。现在,当站中发生事件时,我正在使用 spring AOP 记录它。
另一方面,我有一个客户。客户端是一个 Web 应用程序。因此,当用户想查看车站是否有出租车(我有保存数据的向量)时,他单击一个按钮,然后 servlet 从服务器询问信息,然后显示所需的 jsp 页面和信息. 如果向量是空的,它可以正常工作,但是即使只有一个元素,我也会遇到异常。
这是我的代码:
服务器端:
应用程序上下文.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<aop:aspectj-autoproxy>
<aop:include name="Logging"/>
</aop:aspectj-autoproxy>
<bean id="Logging" class="pack.aop.Logging"/>
<bean id="Station" class="pack.bl.Station" scope ="prototype" lazy-init="true"/>
服务器管理员:
public MyServer()
{
al = new ArrayList<ClientHandler>();
try {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
si = (StationInterface)ctx.getBean("Station",StationInterface.class);
} catch (SecurityException e) {
e.printStackTrace();
}
}
SI 是站接口(我有实现这个接口的站类)
客户端处理程序
ClientHandler(Socket client)
{
this.socket = client;
try{
to_client = new ObjectOutputStream(socket.getOutputStream());
from_client = new ObjectInputStream(socket.getInputStream());
si.set_server(MyServer.this);
}
catch(IOException ioe)
{
// error when create the streams
return;
}
}
public void run(){
boolean is_running = true;
try
{
data_from_client = (Vector)from_client.readObject();
if (data_from_client.elementAt(0).equals("taxis_waits") &&
data_from_client.elementAt(1).equals("taxis_break"))
{
Object t_b = si.get_taxis_on_break();
Object t_w = si.get_taxis_on_waiting();
to_client.writeObject(t_w);
to_client.writeObject(t_b);
to_client.flush();
}
else if (data_from_client.elementAt(0).equals("all_passengers"))
{
Object x = si.get_passengesrs();
to_client.writeObject(x);
to_client.flush();
}
}
}
注意:方法:get_taxis_on_break()、get_taxis_on_waiting() 和 get_passengers(),返回 Vector。(出租车或乘客)所以当向量为空时,它似乎工作正常,服务器将数据写入 servlet,servlet 读取它很好,但是当有一个元素时,我在客户端遇到异常(小服务程序(WebApplication)):
例外:
SEVERE: Servlet.service() for servlet [pack.servlets.servlet2] in context with path
[/TaxiWeb] threw exception
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException:
org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at pack.servlets.servlet2.doPost(servlet2.java:90)
at pack.servlets.servlet2.doGet(servlet2.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.NotSerializableException:
org.springframework.aop.aspectj.annotation.InstantiationModelAwarePointcutAdvisorImpl
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeArray(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeArray(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.access$300(Unknown Source)
at java.io.ObjectOutputStream$PutFieldImpl.writeFields(Unknown Source)
at java.io.ObjectOutputStream.writeFields(Unknown Source)
at java.util.Vector.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at pack.my_server.MyServer$ClientHandler.run(MyServer.java:186)