From 1d8063cd7c7c63762f340be898a25c33bc20e0de Mon Sep 17 00:00:00 2001 From: mmagi Date: Tue, 6 Jun 2023 09:47:32 +0800 Subject: [PATCH] fix: DingTalkImpl image url not readable in SpEL --- .../tools/robot/vendor/DingTalkImpl.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/vendor/DingTalkImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/vendor/DingTalkImpl.java index 08eb0a58..01b02ef5 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/vendor/DingTalkImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/tools/robot/vendor/DingTalkImpl.java @@ -21,7 +21,9 @@ import lombok.extern.slf4j.Slf4j; import org.cloud.sonic.controller.tools.robot.Message; import org.cloud.sonic.controller.tools.robot.RobotMessenger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; import org.springframework.expression.Expression; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -44,14 +46,19 @@ @Service("DingTalkImpl") public class DingTalkImpl implements RobotMessenger { - @Value("${robot.img.success}") - private String successUrl; - //警告时的图片url - @Value("${robot.img.warning}") - private String warningUrl; - //失败时的图片url - @Value("${robot.img.error}") - private String errorUrl; + @Configuration + static class DingTalkMsgExt { + @Value("${robot.img.success}") + public String successUrl; + //警告时的图片url + @Value("${robot.img.warning}") + public String warningUrl; + //失败时的图片url + @Value("${robot.img.error}") + public String errorUrl; + } + @Autowired + private DingTalkMsgExt ext; Expression templateTestSuiteMessage = RobotMessenger.parseTemplate(""" #{ @@ -128,7 +135,7 @@ private void signAndSend(RestTemplate restTemplate, String token, String secret, @Override public void sendMessage(RestTemplate restTemplate, String token, String secret, Expression messageTemplate, Message msg) { - msg.ext = this; + msg.ext = ext; Map content = messageTemplate.getValue(ctx, msg, Map.class); this.signAndSend(restTemplate, token, secret, content); }