Daizc
count.articles52
count.tags25
count.categories3
Java Stream Reduce 注意事项

Java Stream Reduce 注意事项

使用JDBC操作Postgre时jsonb操作符被识别为参数的问题

使用JDBC操作Postgre时jsonb操作符被识别为参数的问题

使用JDBC操作Postgre时jsonb操作符被识别为参数的问题

一句话解决方式

把sql中的?替换为??,就能解决

原SQL

1
2
-- 可以在pgClient中正常执行
SELECT * FROM project WHERE (tags ?& array['Sonar'])

现SQL

1
2
-- 可以通过org.postgresql.Driver正常执行
SELECT * FROM project WHERE (tags ??& array['Sonar'])
解决Springdoc-OAS3中Schema重复的问题

解决Springdoc-OAS3中Schema重复的问题

在使用springdoc-openapi时,如果项目中存在多个SimpleName一致的Class,
那在Schema描述中将会依照解析的先后顺序互相覆盖,从而导致Api文档的描述与预期不一致。

相似问题

解决方案

  • 启用springdoc.use-fqn属性,所有的类将解析为全限定名
  • 重写TypeNameResolver,自定义解析规则
由XXL-admin日志序列化异常导致的事故

由XXL-admin日志序列化异常导致的事故

原因分析

  1. 客户端回调日志序列化出现问题
  2. 服务端收到callback后反序列化失败抛出500
  3. 客户端收到500错误码无限重试
  4. 由于配置错误多个客户端扫描了NFS上同一个日志目录
  5. 多个客户端重试同一条日志,错误被放大
  6. 服务端错误日志中打印了出入参,由于大量客户端重发callback,日志狂刷
  7. xxl服务端日志滚动规则仅仅配置了日期滚动,未配置按大小滚动,错误兜底失败
  8. 服务器用于存储日志的磁盘爆满,所有服务都爆炸啦!!(高兴
搭建Maven脚手架时一些并不太常见的问题

搭建Maven脚手架时一些并不太常见的问题

[DEBUG日记]Swagger扫不到类-Jdk代理导致的反射类型故障

[DEBUG日记]Swagger扫不到类-Jdk代理导致的反射类型故障

先说结论

jdk代理的问题,换用cglib代理就好了。随便找个配置类,加上 @EnableAspectJAutoProxy注解即可解决。

解决由https转发导致的SpringCloudGateway转发异常

解决由https转发导致的SpringCloudGateway转发异常

错误日志如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
2021-07-27 15:51:31.302  WARN [TID:TID-1419928421240946688][PID:1][or-http-epoll-2] r.netty.http.client.HttpClientConnect    [299]: [id: 0xe9859259, L:/10.42.8.227:41228 ! R:10.42.4.120/10.42.4.120:8080] The connection observed an error

io.netty.handler.codec.DecoderException: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 485454502f312e31203430302042616420526571756573740d0a436f6e74656e742d4c656e6774683a20300d0a436f6e6e656374696f6e3a20636c6f73650d0a0d0a
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:477)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:795)
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:480)
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 485454502f312e31203430302042616420526571756573740d0a436f6e74656e742d4c656e6774683a20300d0a436f6e6e656374696f6e3a20636c6f73650d0a0d0a
at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1213)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ com.alibaba.csp.sentinel.adapter.spring.webflux.SentinelWebFluxFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP GET "/某个service/v2/api-docs" [ExceptionHandlingWebHandler]
Stack trace:
at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1213)
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1280)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:507)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:446)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:795)
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:480)
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
定制Jackson注解实现字段脱敏

定制Jackson注解实现字段脱敏

功能

在保证jackson原注解不失效的前提下,通过自定义注解对POJO中部分指定的字段进行自定义处理

完成样式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class Test {

public static void main(String[] args) throws JsonProcessingException {

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setAnnotationIntrospector(new EnhanceJacksonAnnotationIntrospector());
A a = new A();
a.setAge(10);
a.setName("ASDASDASD");
a.setRemark("REMARK!");
a.setMobile("17600000000");
System.out.println(objectMapper.writeValueAsString(a));
}


@Data
static class A {

private String name;

private Integer age;

private String remark;

@JsonMask(a = "",b = "",c = "")
private String mobile;
}
}

运行结果

1
{"name":"ASDASDASD","age":10,"remark":"REMARK!","mobile":"1760****000"}
改造Spring-data-redis 优雅设置过期时间

改造Spring-data-redis 优雅设置过期时间

Spring-data-redis是一个比较优雅的缓存解决方案,只需要在对应的方法上打上注解就可以便捷的将数据放入redis。

但Spring-data-redis中配置TTL只能按照cacheName的维度进行配置,并不能精确到具体的接口上。

比如以下需求就不能优雅的实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public interface CacheDemo{

// 这个接口只缓存30min
@Cacheable(value = "user", keyGenerator = "xxxx")
List<User> listByQuery(UserQuery query);

// 这个接口只缓存1min
@Cacheable(value = "user", keyGenerator = "xxxx")
List<User> takeUserFromObj(Object obj);

// 这个接口缓存180min
@Cacheable(value = "user", keyGenerator = "xxxx")
List<User> getByUserId(String userId);
}

这篇文章就将以定制Cache具体实现类的方式优雅的实现这个功能.

java8函数设计[1]-在filter中根据Key去重的函数

java8函数设计[1]-在filter中根据Key去重的函数

函数接口是如何写出来的?