编程语言
首页 > 编程语言> > Java中的异常错误汇总

Java中的异常错误汇总

作者:互联网

目录

1.使用rmi测试发生的异常

2.Mybatis执行sql语句参数错误


1.使用rmi测试发生的异常

java.rmi.server.ExportException: remote object implements illegal remote interface; nested exception is: 
	java.lang.IllegalArgumentException: illegal remote method encountered: public abstract java.lang.String com.righteye.remote.IHello.sayHello(java.lang.String)
	at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:228)
	at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:383)
	at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:320)
	at java.rmi.server.UnicastRemoteObject.<init>(UnicastRemoteObject.java:198)
	at java.rmi.server.UnicastRemoteObject.<init>(UnicastRemoteObject.java:180)
	at com.righteye.remote.impl.IHelloImpl.<init>(IHelloImpl.java:10)
	at com.righteye.remote.impl.RmiServer.main(RmiServer.java:15)
Caused by: java.lang.IllegalArgumentException: illegal remote method encountered: public abstract java.lang.String com.righteye.remote.IHello.sayHello(java.lang.String)
	at sun.rmi.server.Util.checkMethod(Util.java:267)
	at sun.rmi.server.Util.getRemoteInterfaces(Util.java:246)
	at sun.rmi.server.Util.getRemoteInterfaces(Util.java:216)
	at sun.rmi.server.Util.createProxy(Util.java:146)
	at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:226)
	... 6 more

解决方案:

注册远程调用的服务需要 throws RemoteException

public interface IHello extends Remote {

    public String sayHello(String name) throws RemoteException;
}

public class IHelloImpl extends UnicastRemoteObject implements IHello {
    protected IHelloImpl() throws RemoteException {
        super();
    }

    @Override
    public String sayHello(String name) throws RemoteException {

        return "Hello" + name;
    }
}

2.Mybatis执行sql语句参数错误

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'myname' not found. Available parameters are [arg1, arg0, param1, param2]
### The error may exist in com/righteye/day01/dao/UserDao.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: insert into user(username, password) values(?, ?)
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'myname' not found. Available parameters are [arg1, arg0, param1, param2]

        解决方案:参数名不匹配问题,当传入多个参数的时候,可以使用对象的形式进行传参,使用对象属性名进行赋值;如果使用基本数据类型,可以在接口方法声明的参数前加上Param(自定义参数名) 给参数起别名

 int insertUser(@Param("myname")String username, @Param("pwd")String password);
    <insert id="insertUser">
        insert into user(username, password) values(#{myname}, #{pwd})
    </insert>

标签:Java,String,错误,UnicastRemoteObject,汇总,server,Util,java,rmi
来源: https://blog.csdn.net/qq_45888932/article/details/122365048