Spring 针对远程访问服务提供的一个remote包其的的是提供一套统一的远程服务发布功能
先来看一下Spring支持那些远程服务功能 RMI服务 Hessian或者Burlap通过HTTP远程调用服务 HTTP调用器暴露服务
下面用一个例子来看一下Spring 是怎样对这些服务进行统一的封装和管理
先看一下服务器端的源代码
public interface IBookService {
Book getById(String id);
}
public class Book {
public String name;
public String id;
public String author;
}
public class BookService implements IBookService {
public Book getById(String id) {
return BookStoregetById(id);
}
}
客户端源代码
public class BookQueryService {
private IBookService bookService;
public void setAccountService(IBookService bookService) {
thisbookService = bookService;
}
public Book getBookById(String id) {
return bookServicegetById(id);
}
}
//客户端调用示例
public static void main(String[] args) {
ClassPathXmlApplicationContext context;
context = new ClassPathXmlApplicationContext(applicationContextxml);
BookQueryService bookQueryService = (BookQueryService) contextgetBean(bookQueryService);
Book book = bookQueryServicegetBookById();
}
[] [] []