java.lang.NoClassDefFoundError: org/omg/CORBA/COMM_FAILURE on client while creating simple spring boor rmi app
java.lang.NoClassDefFoundError: org/omg/CORBA/COMM_FAILURE on client while creating simple spring boor rmi app
我正在创建 spring 使用服务器上的 RmiServiceExporter 和 client.When 上的 RmiProxyFactoryBean 启动应用程序 我启动服务器一切正常,我得到
[main] o.s.remoting.rmi.RmiServiceExporter: Binding service 'ServerServiceIF' to RMI registry: RegistryImpl[UnicastServerRef [liveRef: [endpoint:[localhost:1099](local),objID:[0:0:0, 0]]]]
然后我启动我的客户端,它也是 spring 启动应用程序,客户端上的服务接口连接到本地主机上的地址。
rmi://localhost:1099/ServerServiceIF
但是当我尝试调用这个接口的方法时我得到
Exception in thread "main" java.lang.NoClassDefFoundError: org/omg/CORBA/COMM_FAILURE
at org.springframework.remoting.rmi.RmiClientInterceptorUtils.isCorbaConnectFailure(RmiClientInterceptorUtils.java:187)
at org.springframework.remoting.rmi.RmiClientInterceptorUtils.isConnectFailure(RmiClientInterceptorUtils.java:174)
at org.springframework.remoting.rmi.RmiClientInterceptor.isConnectFailure(RmiClientInterceptor.java:283)
at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:349)
at org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:260)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy38.auth(Unknown Source)
at com.cw.client.ClientApplication.main(ClientApplication.java:29)
Caused by: java.lang.ClassNotFoundException: org.omg.CORBA.COMM_FAILURE
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 9 more
这是我的服务器和客户端:
ServerApplication.java
package com.cw.server;
import com.cw.appif.ServerServiceIF;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.rmi.RmiServiceExporter;
@SpringBootApplication
public class ServerApplication {
@Bean
ServerServiceIF serverServiceIF() {
return new ServerService();
}
@Bean
RmiServiceExporter exporter(ServerServiceIF implementation) {
// Expose a service via RMI. Remote object URL is:
// rmi://<HOST>:<PORT>/<SERVICE_NAME>
// 1099 is the default port
Class<ServerServiceIF> serviceInterface = ServerServiceIF.class;
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setServiceInterface(serviceInterface);
exporter.setService(implementation);
exporter.setServiceName(serviceInterface.getSimpleName());
exporter.setRegistryPort(1099);
return exporter;
}
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}
ClientApplication.java
package com.cw.client;
import com.cw.appif.ServerServiceIF;
import com.cw.exceptions.AuthException;
import com.cw.models.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
@SpringBootApplication
public class ClientApplication {
private static User user;
@Bean
RmiProxyFactoryBean service() {
RmiProxyFactoryBean rmiProxyFactory = new RmiProxyFactoryBean();
rmiProxyFactory.setServiceUrl("rmi://localhost:1099/ServerServiceIF");
rmiProxyFactory.setServiceInterface(ServerServiceIF.class);
return rmiProxyFactory;
}
public static void main(String[] args) {
try {
ServerServiceIF service = SpringApplication.run(ClientApplication.class, args).
getBean(ServerServiceIF.class);
user = new User("Denis","1234","e@mail.co");
service.auth(user);
System.out.println("User authed");
} catch (AuthException e) {
e.printStackTrace();
}
}
}
我的服务器服务接口和在服务器上的实现:
package com.cw.appif;
import com.cw.exceptions.AuthException;
import com.cw.models.User;
public interface ServerServiceIF{
boolean auth(User user) throws AuthException;
}
package com.cw.server;
import com.cw.appif.ServerServiceIF;
import com.cw.exceptions.AuthException;
import com.cw.models.User;
import java.util.List;
public class ServerService implements ServerServiceIF{
static List<User> clients;
@Override
public boolean auth(User user) throws AuthException {
clients.add(user);
System.out.println("hi");
return true;
}
}
这是我的想法:
1)可能是因为我使用的接口在客户端和服务器上完全一样,但是客户端找不到class,因为路径不同?
2)当我调试我的客户端服务时->h->建议->targetSource ->targetClass 为空。可以吗?我将在下面的调试中上传我的项目结构和这个变量的屏幕截图。
server structure
client structure
debugging client
找到问题了。将 corba 添加到 classpath 后,我发现 class User 必须是 Serializable
。添加 implements Serializable
和 serialVersionUID
解决了问题,现在一切正常。
我正在创建 spring 使用服务器上的 RmiServiceExporter 和 client.When 上的 RmiProxyFactoryBean 启动应用程序 我启动服务器一切正常,我得到
[main] o.s.remoting.rmi.RmiServiceExporter: Binding service 'ServerServiceIF' to RMI registry: RegistryImpl[UnicastServerRef [liveRef: [endpoint:[localhost:1099](local),objID:[0:0:0, 0]]]]
然后我启动我的客户端,它也是 spring 启动应用程序,客户端上的服务接口连接到本地主机上的地址。
rmi://localhost:1099/ServerServiceIF
但是当我尝试调用这个接口的方法时我得到
Exception in thread "main" java.lang.NoClassDefFoundError: org/omg/CORBA/COMM_FAILURE
at org.springframework.remoting.rmi.RmiClientInterceptorUtils.isCorbaConnectFailure(RmiClientInterceptorUtils.java:187)
at org.springframework.remoting.rmi.RmiClientInterceptorUtils.isConnectFailure(RmiClientInterceptorUtils.java:174)
at org.springframework.remoting.rmi.RmiClientInterceptor.isConnectFailure(RmiClientInterceptor.java:283)
at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:349)
at org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:260)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy38.auth(Unknown Source)
at com.cw.client.ClientApplication.main(ClientApplication.java:29)
Caused by: java.lang.ClassNotFoundException: org.omg.CORBA.COMM_FAILURE
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 9 more
这是我的服务器和客户端:
ServerApplication.java
package com.cw.server;
import com.cw.appif.ServerServiceIF;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.rmi.RmiServiceExporter;
@SpringBootApplication
public class ServerApplication {
@Bean
ServerServiceIF serverServiceIF() {
return new ServerService();
}
@Bean
RmiServiceExporter exporter(ServerServiceIF implementation) {
// Expose a service via RMI. Remote object URL is:
// rmi://<HOST>:<PORT>/<SERVICE_NAME>
// 1099 is the default port
Class<ServerServiceIF> serviceInterface = ServerServiceIF.class;
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setServiceInterface(serviceInterface);
exporter.setService(implementation);
exporter.setServiceName(serviceInterface.getSimpleName());
exporter.setRegistryPort(1099);
return exporter;
}
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}
ClientApplication.java
package com.cw.client;
import com.cw.appif.ServerServiceIF;
import com.cw.exceptions.AuthException;
import com.cw.models.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
@SpringBootApplication
public class ClientApplication {
private static User user;
@Bean
RmiProxyFactoryBean service() {
RmiProxyFactoryBean rmiProxyFactory = new RmiProxyFactoryBean();
rmiProxyFactory.setServiceUrl("rmi://localhost:1099/ServerServiceIF");
rmiProxyFactory.setServiceInterface(ServerServiceIF.class);
return rmiProxyFactory;
}
public static void main(String[] args) {
try {
ServerServiceIF service = SpringApplication.run(ClientApplication.class, args).
getBean(ServerServiceIF.class);
user = new User("Denis","1234","e@mail.co");
service.auth(user);
System.out.println("User authed");
} catch (AuthException e) {
e.printStackTrace();
}
}
}
我的服务器服务接口和在服务器上的实现:
package com.cw.appif;
import com.cw.exceptions.AuthException;
import com.cw.models.User;
public interface ServerServiceIF{
boolean auth(User user) throws AuthException;
}
package com.cw.server;
import com.cw.appif.ServerServiceIF;
import com.cw.exceptions.AuthException;
import com.cw.models.User;
import java.util.List;
public class ServerService implements ServerServiceIF{
static List<User> clients;
@Override
public boolean auth(User user) throws AuthException {
clients.add(user);
System.out.println("hi");
return true;
}
}
这是我的想法:
1)可能是因为我使用的接口在客户端和服务器上完全一样,但是客户端找不到class,因为路径不同?
2)当我调试我的客户端服务时->h->建议->targetSource ->targetClass 为空。可以吗?我将在下面的调试中上传我的项目结构和这个变量的屏幕截图。
server structure
client structure
debugging client
找到问题了。将 corba 添加到 classpath 后,我发现 class User 必须是 Serializable
。添加 implements Serializable
和 serialVersionUID
解决了问题,现在一切正常。