Spring boot with Hessian
时间:2022-05-03
本文章向大家介绍Spring boot with Hessian,主要内容包括节选自《Netkiller Java 手札》一书、5.20. Spring boot with Hessian、5.20.2. Application、5.20.3. HessianServiceExporter、5.20.4. Service、5.20.5. RestController、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。
节选自《Netkiller Java 手札》一书
5.20. Spring boot with Hessian
5.20.1. Maven
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.38</version>
</dependency>
5.20.2. Application
package cn.netkiller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan
// @EnableMongoRepositories
// @EnableJpaRepositories
@EnableScheduling
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
5.20.3. HessianServiceExporter
package cn.netkiller.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.caucho.HessianProxyFactoryBean;
//import org.springframework.remoting.caucho.HessianProxyFactoryBean;
import org.springframework.remoting.caucho.HessianServiceExporter;
import cn.netkiller.service.HelloWorldService;
@Configuration
public class HessionConfig {
@Autowired
private HelloWorldService helloWorldService;
@Bean(name = "/HelloWorldService")
public HessianServiceExporter hessianServiceExporter() {
HessianServiceExporter exporter = new HessianServiceExporter();
exporter.setService(helloWorldService);
exporter.setServiceInterface(HelloWorldService.class);
return exporter;
}
@Bean
public HessianProxyFactoryBean helloClient() {
HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
factory.setServiceUrl("http://localhost:7000/HelloWorldService");
factory.setServiceInterface(HelloWorldService.class);
return factory;
}
}
5.20.4. Service
package cn.netkiller.service;
public interface HelloWorldService {
String sayHello(String name);
}
package cn.netkiller.service.impl;
import org.springframework.stereotype.Component;
import cn.netkiller.service.HelloWorldService;
@Component
public class HelloWorldServiceImpl implements HelloWorldService {
@Override
public String sayHello(String name) {
return "Hello World! " + name;
}
}
5.20.5. RestController
package cn.netkiller.rest.hession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.netkiller.service.HelloWorldService;
@RestController
@RequestMapping("/public/hession")
public class TestRestController {
@Autowired
HelloWorldService helloWorldService;
@RequestMapping("/hello")
public String test() {
return helloWorldService.sayHello("Spring boot with Hessian.");
}
}
- java教程
- Java快速入门
- Java 开发环境配置
- Java基本语法
- Java 对象和类
- Java 基本数据类型
- Java 变量类型
- Java 修饰符
- Java 运算符
- Java 循环结构
- Java 分支结构
- Java Number类
- Java Character类
- Java String类
- Java StringBuffer和StringBuilder类
- Java 数组
- Java 日期时间
- Java 正则表达式
- Java 方法
- Java 流(Stream)、文件(File)和IO
- Java 异常处理
- Java 继承
- Java 重写(Override)与重载(Overload)
- Java 多态
- Java 抽象类
- Java 封装
- Java 接口
- Java 包(package)
- Java 数据结构
- Java 集合框架
- Java 泛型
- Java 序列化
- Java 网络编程
- Java 发送邮件
- Java 多线程编程
- Java Applet基础
- Java 文档注释
- 一个价值百万的思路,如何下载去水印视频
- Go语言入门(十) Mysql与Redis操作
- 【Vue进阶】——如何实现组件属性透传?
- Go语言入门(九) 文件操作
- zookeeper完整详细版
- redis学习(十九)
- Android开发6年,互联网寒冬公司倒闭后,耗时3个月北上广求职,终拿到头条Offer!
- 直播软件开发如何使用FFMPEG推流并保存在本地
- react-router学习笔记
- 尤大 3 天前发在 GitHub 上的 vue-lit 是啥?
- BFE.dev前端刷题 23. 实现一个sum()方法
- 彻底深刻理解js原型链之prototype,proto以及constructor(一)
- SAP Spartacus取cart的HTTP请求
- 记一次Netty连接池FixedChannelPool连接未释放问题的排查总结
- 神经网络中的蒸馏技术,从Softmax开始说起