Java RMI远程调用需要定义远程接口并继承Remote接口,注册并发布远程服务,步骤比较麻烦。Spring框架目的在与减少开发人员重复编码模版代码,简化步骤,让开发人员用简洁的代码开发出良好的安全性高的代码,因此Spring对Java RMI做了良好的封装,大大简化了Java RMI的开发步骤。
Maven 项目搭建:
项目中用来的依赖包
maven pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>
</dependencies>
项目中用到的实体类Spitter.java
package com.spittr.entity;
import java.io.Serializable;
public class Spitter implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1563056272025335248L;
private Long id;
private String username;
private String password;
private String firstName;
private String lastName;
private String email;
public Spitter() {}
public Spitter(String username, String password, String firstName, String lastName, String email) {
this(null, username, password, firstName, lastName, email);
}
public Spitter(Long id