0%

RequestBodyAdvice和ResponseBodyAdvice

有两个接口

RequestBodyAdviceResponseBodyAdvice 在spring4中新添加的两个接口

RequestBodyAdvice接口

该接口是在获取@RequestBody参数数据之前进行处理的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public interface RequestBodyAdvice {


boolean supports(MethodParameter methodParameter, Type targetType,
Class<? extends HttpMessageConverter<?>> converterType);


Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType);


HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException;


Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType);

}

ResponseBodyAdvice接口

该接口是在消息体被HttpMessageConverter消息解析器写入之前执行的

1
2
3
4
5
6
7
8
9
10
11
public interface ResponseBodyAdvice<T> {


boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType);


T beforeBodyWrite(T body, MethodParameter returnType, MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType,
ServerHttpRequest request, ServerHttpResponse response);

}

数据备份和恢复

什么情况下会用到数据备份呢

数据丢失的场景

  • 人为误操作造成的某些数据被误操作
  • 软件BUG造成数据部分或者全部丢失
  • 硬件故障造成数据库部分或全部丢失
  • 安全漏洞被入侵数据恶意破坏

非数据丢失场景

  • 基于某个时间点的数据恢复
  • 开发测试环境数据库搭建
  • 相同数据库的新环境搭建
  • 数据库或者数据迁移
阅读全文 »

属性绑定原理

注意:使用版本为spring-boot-2.2.2.RELEASE

在进行自定义配置的时候,我们通常使用@ConfigurationProperties注解来进行配置文件和配置类的映射,为什么可以映射呢?

主要靠的是@EnableConfigurationProperties注解来进行自动的将外部配置绑定到@ConfigurationProperties标注的类的属性中

1
2
3
4
5
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(EnableConfigurationPropertiesRegistrar.class)
public @interface EnableConfigurationProperties
阅读全文 »

Netty接收请求过程

由于Netty用来进行接收请求和处理请求的是两个线程组,那么两个线程组是如何进行交互来处理请求的呢

1
2
3
4
5
6
// bossGroup用于接收Client端连接,会将请求交给workerGroup
// bossGroup的线程数建议设置为1,因为仅负责接收客户端的连接,不做复杂的逻辑处理,可以尽少的占用资源
// NioEventLoopGroup中的子线程数默认是cpu核数*2
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
// workerGroup会获取到真正的连接,然后和连接进行通信,workerGroup用于实际业务处理的
EventLoopGroup workerGroup = new NioEventLoopGroup();
阅读全文 »

SOAP

SOAP使用基于XML表示RPC调用及其参数和返回值