From f126ffe6c5e62300cc2427ad9ee0c28d2c1412ae Mon Sep 17 00:00:00 2001 From: Schwi <1252237203@qq.com> Date: Sat, 22 Jul 2023 18:05:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9ParserContext=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=AE=9E=E7=8E=B0=EF=BC=8C=E8=A7=A3=E5=86=B3`@DS("#{T?= =?UTF-8?q?(pkg.A).B()}")`=E6=8A=A5=E9=94=99`org.springframework.expressio?= =?UTF-8?q?n.spel.SpelParseException:=20Expression=20[#{T(pkg.A).B()}]=20@?= =?UTF-8?q?1:=20EL1043E:=20Unexpected=20token.=20Expected=20'identifier'?= =?UTF-8?q?=20but=20was=20'lcurly({)'`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../processor/DsSpelExpressionProcessor.java | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/processor/DsSpelExpressionProcessor.java b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/processor/DsSpelExpressionProcessor.java index 03c6c36d..081d3c79 100644 --- a/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/processor/DsSpelExpressionProcessor.java +++ b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/processor/DsSpelExpressionProcessor.java @@ -50,24 +50,9 @@ public class DsSpelExpressionProcessor extends DsProcessor { * 对于默认不设置的情况下,从参数中取值的方式 #param1 * 设置指定模板 ParserContext.TEMPLATE_EXPRESSION 后的取值方式: #{#param1} * issues: https://github.com/baomidou/dynamic-datasource-spring-boot-starter/issues/199 + * issues: https://github.com/baomidou/dynamic-datasource-spring-boot-starter/issues/485 */ - private ParserContext parserContext = new ParserContext() { - - @Override - public boolean isTemplate() { - return false; - } - - @Override - public String getExpressionPrefix() { - return null; - } - - @Override - public String getExpressionSuffix() { - return null; - } - }; + private ParserContext parserContext = ParserContext.TEMPLATE_EXPRESSION; private BeanResolver beanResolver; @Override From 9c318cca874c8654c5b985f7b65bcdab390d4a92 Mon Sep 17 00:00:00 2001 From: Schwi <1252237203@qq.com> Date: Sat, 22 Jul 2023 18:09:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=90=8D?= =?UTF-8?q?=E6=98=BE=E7=84=B6=E5=BA=94=E8=AF=A5=E6=98=AFString?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/processor/DsSpelExpressionProcessor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/processor/DsSpelExpressionProcessor.java b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/processor/DsSpelExpressionProcessor.java index 081d3c79..6f42c170 100644 --- a/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/processor/DsSpelExpressionProcessor.java +++ b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/processor/DsSpelExpressionProcessor.java @@ -67,8 +67,7 @@ public String doDetermineDatasource(MethodInvocation invocation, String key) { ExpressionRootObject rootObject = new ExpressionRootObject(method, arguments, invocation.getThis()); StandardEvaluationContext context = new MethodBasedEvaluationContext(rootObject, method, arguments, NAME_DISCOVERER); context.setBeanResolver(beanResolver); - final Object value = PARSER.parseExpression(key, parserContext).getValue(context); - return value == null ? null : value.toString(); + return PARSER.parseExpression(key, parserContext).getValue(context, String.class); } /**