Chuenhung的个人网站

chuenhung.github.io

需求

项目中共用了一个Redis,而项目中部分代码使用了JetCache的@Cached注解。所以需要给@Cached动态配置area属性值,用来区分dev和test环境。

问题

自定义注解的属性值需要常量值,即static final修饰,直接通过配置文件不可行。

解决方案

1、使用AOP切面拦截使用注解的方法,动态修改注解的属性值。切面1。
2、注解的底层一般也有一个AOP切面。切面2。
需要确保切面1在切面2之前执行 (使用@order(int)注解,值越小越先执行)。

阅读全文 »

SpringBoot校验List失效解决方法

失效场景示例代码:

1
2
3
4
5
6
7
8
9
10
11
12
@RestController
@RequestMapping("/v1/jx/flowSummary")
@Slf4j
public class JxFlowSummaryController {

@Operation(summary = "批量修改原始得分")
@PostMapping("/updateScore")
public ResponseDto batchUpdateScore(@RequestBody @Valid List<BatchUpdateScoreDto> dtoList) {
// jxFlowSummaryService.batchUpdateScore(dtoList);
return ResponseUtil.wrapSuccess(null);
}
}

解决方法一:在controller上加上@Validated注解

1
2
3
4
5
6
7
8
9
10
11
12
@RestController
@RequestMapping("/v1/jx/flowSummary")
@Slf4j
@Validated
public class JxFlowSummaryController {

@Operation(summary = "批量修改原始得分")
@PostMapping("/updateScore")
public ResponseDto batchUpdateScore(@RequestBody @Valid List<BatchUpdateScoreDto> dtoList){
return ResponseUtil.wrapSuccess(null);
}
}
阅读全文 »

狂神说-Elasticsearch 7.6入门学习笔记

狂神说-Elasticsearch 7.6入门学习笔记

Windows Elasticsearch IK分词器插件启动报错

错误如下:

1
java.security.Acces ControlException: access denied (\ik\config\IKAnalyzer.cfg.xml" "read")

原因:
D:\Program Files文件夹下的所有文件默认都是只读权限。
解决方法:
Elasticsearch不要安装在 Program Files 、Program Files (x86) 这些目录下。

参考链接

阅读全文 »
0%