Skip to content

Commit

Permalink
1. 修改ParserContext默认实现,解决@DS("#{T(pkg.A).B()}")报错`org.springframewo…
Browse files Browse the repository at this point in the history
…rk.expression.spel.SpelParseException: Expression [#{T(pkg.A).B()}] @1: EL1043E: Unexpected token. Expected 'identifier' but was 'lcurly({)'`

2. 数据库名肯定是字符串,所以可以大胆点指定Class
  • Loading branch information
cyb233 committed Mar 14, 2023
1 parent d0300b5 commit 57e3834
Showing 1 changed file with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,8 @@ public class DsSpelExpressionProcessor extends DsProcessor {
* 设置指定模板 ParserContext.TEMPLATE_EXPRESSION 后的取值方式: #{#param1}
* issues: https://github.com/baomidou/dynamic-datasource-spring-boot-starter/issues/199
*/
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
Expand All @@ -80,8 +65,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);
}

public void setParserContext(ParserContext parserContext) {
Expand Down

0 comments on commit 57e3834

Please sign in to comment.