Spring-RMI 事件导致 java.io.InvalidClassException: filter status: REJECTED

ste*_*hew 5 java spring java-8

问题

项目使用 RMI 时 Spring 4.3.3 和 Java 8 的问题。应用程序在使用 RMI 向其他应用程序发送事件时抛出异常。它运行良好(应用程序已有几年历史)但在 Weblogic 服务器上安装了一些补丁后它坏了。

编码

应用程序使用 spring-context

org.springframework.context.support.AbstractApplicationContext

 private void publishEvent(final ApplicationEvent event) {
        taskExecutor.submit(new Runnable() {
            @Override
            public void run() {
                publisher.publishEvent(event);
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

日志

> 2019-10-01 10:42:14,366 ERROR .c.b.i.i.ImportServiceImpl - An unexpected error occurred during the synchronous import process.
org.springframework.remoting.RemoteLookupFailureException: Lookup of RMI stub failed; nested exception is java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
        java.io.InvalidClassException: filter status: REJECTED
        at org.springframework.remoting.rmi.RmiClientInterceptor.lookupStub(RmiClientInterceptor.java:215)
        at org.springframework.remoting.rmi.RmiClientInterceptor.getStub(RmiClientInterceptor.java:237)
        at org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:258)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

(...)       


>   Caused by: java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
        java.io.InvalidClassException: filter status: REJECTED
        at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:125)
        at java.rmi.Naming.lookup(Naming.java:101)
        at org.springframework.remoting.rmi.RmiClientInterceptor.lookupStub(RmiClientInterceptor.java:200)
        ... 104 common frames omitted
Caused by: java.io.InvalidClassException: filter status: REJECTED
        at java.io.ObjectInputStream.filterCheck(ObjectInputStream.java:1255)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1878)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1751)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2042)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2287)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2211)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2069)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:431)
        at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:123)
        ... 106 common frames omitted
Run Code Online (Sandbox Code Playgroud)

小智 3

我在类似的情况下使用了上面提出的解决方案,它对我有用:

JAVA_OPTIONS="${JAVA_OPTIONS} -Dweblogic.oif.serialFilterScope=weblogic
Run Code Online (Sandbox Code Playgroud)

您可以在此处找到 Weblogic 设置的描述。