首页 / 软件开发 / JAVA / Spring 2提供的remote包学习笔记
Spring 2提供的remote包学习笔记2011-09-14Spring2 针对远程访问服务,提供的一个remote包。其的的是提供一套统一的远程服务发布功能。先来看一下Spring2支持那些远程服务功能:1. RMI服务2. Hessian或者Burlap通过HTTP远程调用服务3. HTTP调用器暴露服务下面用一个例子,来看一下Spring2 是怎样对这些服务进行统一的封装和管理。先看一下服务器端的源代码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 BookStore.getById(id);
}
}客户端源代码public class BookQueryService {
private IBookService bookService;
public void setAccountService(IBookService bookService) {
this.bookService = bookService;
}
public Book getBookById(String id) {
return bookService.getById(id);
}
}
//客户端调用示例
public static void main(String[] args) {
ClassPathXmlApplicationContext context;
context = new ClassPathXmlApplicationContext("applicationContext.xml");
BookQueryService bookQueryService = (BookQueryService) context.getBean("bookQueryService");
Book book = bookQueryService.getBookById("1");
}