Spring で非同期プロセスを作成する必要がありますが@Async
、メソッドを配置するとこのエラーが発生します
java.io.NotSerializableException: org.springframework.aop.interceptor.AsyncExecutionInterceptor
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
私はこの例を持っていますが、うまくいきません:
@Autowired
private IServicioClienteAsync servicioClienteAsync;
public void prueba() {
//testAsync();
servicioClienteAsync.crearCliente();
}
と
@Service(value = "servicioClienteAsync")
public class ServicioClienteAsync implements Serializable, IServicioClienteAsync {
@Autowired
private WServiceCliente wServiceCliente;
@Override
public void crearCliente() {
wServiceCliente.test("wiiii");
}
}
と
@Component
public class WServiceCliente{
@Async
public void test(String name) {
System.out.println("init ");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("finish");
}
}