springboot 整合hessian(server端)

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

服务器端

pom.xml



    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;
    }
}

代码生成器源码

代码生成器演示

spring boot 2.x 实例源码

你可能感兴趣的:(springboot 整合hessian(server端))