camunda的el表达式解析与srping bean结合

发表于 2021-08-09 17:53:41.207,阅读数:2909

camunda的el表达式解析是基于juel表达式魔改的,基本重写了javax.el这个包,而不是使用java sdk提供的,具体跟javasdk提供的有什么不一样,我没有深入了解

初始化表达式管理器

流程引擎会在初始化流程引擎的时候,通过ProcessEngineFactoryBean对表达式管理器进行初始化,将spring bean和processEngine 的api接口bean放入表达式管理器中,以便表达式进行访问

  protected void initializeExpressionManager() {
    if (processEngineConfiguration.getExpressionManager() == null && applicationContext != null) {
      processEngineConfiguration.setExpressionManager(
          new SpringExpressionManager(applicationContext, processEngineConfiguration.getBeans()));
    }
  }

SpringExpressionManager 继承 ExpressionManager,重写了创建解析器

public class SpringExpressionManager extends ExpressionManager {

  protected ApplicationContext applicationContext;

  /**
   * @param applicationContext
   *          the applicationContext to use. Ignored when 'beans' parameter is
   *          not null.
   * @param beans
   *          a map of custom beans to expose. If null, all beans in the
   *          application-context will be exposed.
   */
  public SpringExpressionManager(ApplicationContext applicationContext, Map<Object, Object> beans) {
    super(beans);
    this.applicationContext = applicationContext;
  }

  @Override
  protected ELResolver createElResolver() {
    CompositeELResolver compositeElResolver = new CompositeELResolver();
    compositeElResolver.add(new VariableScopeElResolver());
    compositeElResolver.add(new VariableContextElResolver());

    if(beans != null) {
      // Only expose limited set of beans in expressions
      compositeElResolver.add(new ReadOnlyMapELResolver(beans));
    } else {
      // Expose full application-context in expressions
      compositeElResolver.add(new ApplicationContextElResolver(applicationContext));
    }

    compositeElResolver.add(new ArrayELResolver());
    compositeElResolver.add(new ListELResolver());
    compositeElResolver.add(new MapELResolver());
    compositeElResolver.add(new BeanELResolver());

    return compositeElResolver;
  }

Terly

面向openAI编程的程序员