JAVA spring hessian_springboot 整合hessian(server端)

本文档展示了如何使用Spring Boot搭建一个基于Hessian的远程服务调用服务器。通过创建`User`和`UserCondition`实体类,定义`IHelloService`接口及其实现`HelloService`,并在主程序中配置`HessianServiceExporter`,实现了远程服务的暴露。示例代码详细解释了每个关键步骤,便于理解Hessian在分布式系统中的应用。
摘要由CSDN通过智能技术生成

hessian 高效的远程调用,分布式的基础,理论自已百度

服务器端

pom.xml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.example

hessianserver

0.0.1-SNAPSHOT

jar

HessianServer

Demo project for Spring Boot

org.springframework.boot

spring-boot-starter-parent

2.0.4.RELEASE

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-web

com.caucho

hessian

4.0.38

org.springframework.boot

spring-boot-maven-plugin

application.properties

server.port = 8080

user.java

package com.example;

import java.io.Serializable;

import java.util.Date;

public class User implements Serializable {

private static final long serialVersionUID = 1L;

private Integer id;

private String name;

private Date birthday;

public User(Integer id, String name, Date birthday) {

super();

this.id = id;

this.name = name;

this.birthday = birthday;

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Date getBirthday() {

return birthday;

}

public void setBirthday(Date birthday) {

this.birthday = birthday;

}

}

userCondition.java

package com.example;

import java.io.Serializable;

import java.util.Date;

public class UserCondition implements Serializable {

private static final long serialVersionUID = 1L;

private Integer id;

private String name;

private Date birthday;

public UserCondition(Integer id, String name, Date birthday) {

super();

this.id = id;

this.name = name;

this.birthday = birthday;

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Date getBirthday() {

return birthday;

}

public void setBirthday(Date birthday) {

this.birthday = birthday;

}

@Override

public String toString() {

return "UserCondition [id=" + id + ", name=" + name + ", birthday=" + birthday + "]";

}

}

IHelloService

package com.example;

import java.util.List;

/**

* @功能描述 Hessian实例之服务器

* @author www.gaozz.club

* @date 2018-08-26

*/

public interface IHelloService {

String sayHello(String name);

List queryList(UserCondition cond);

}

HelloService

package com.example;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;

import org.springframework.stereotype.Service;

/**

* @功能描述 Hessian实例之服务器

* @author www.gaozz.club

* @date 2018-08-26

*/

@Service("HelloService")

public class HelloService implements IHelloService {

@Override

public String sayHello(String name) {

return "Hello World! " + name;

}

@Override

public List queryList(UserCondition cond) {

System.out.println(cond);

List list = new ArrayList<>();

list.add(new User(1, "张三", new Date()));

list.add(new User(2, "李四", new Date()));

return list;

}

}

主程序(重点.....)

package com;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.context.annotation.Bean;

import org.springframework.remoting.caucho.HessianServiceExporter;

import com.example.IHelloService;

/**

* @功能描述 Hessian实例之服务器

* @author www.gaozz.club

* @date 2018-08-26

*/

@SpringBootApplication

public class HessianServer {

@Autowired

private IHelloService service;

public static void main(String[] args) {

SpringApplication.run(HessianServer.class, args);

}

@Bean(name = "/HelloService")

public HessianServiceExporter accountService() {

HessianServiceExporter exporter = new HessianServiceExporter();

exporter.setService(service);

exporter.setServiceInterface(IHelloService.class);

return exporter;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值