使用CDI在流口水规则中注入事实

问题描述 投票:0回答:1

我想在Drools规则引擎中插入一个CDI bean事实。要在普通的Java中做到这一点,我会

@Inject
MyBean myBean;

规则引擎中是否可以@Inject?我需要焊接作为依赖吗?

drools
1个回答
0
投票

只需将其注入调用规则的类(普通Java)中,并在调用规则时将实例传递到工作内存中。

因此,如果您有一个名为RuleInvoker的类,它将调用规则...

public class RuleInvoker {
  @Inject
  MyBean myBean;

  public void invokeRules() {

    KieSession kieSession = ...; 

    kieSession.insert( myBean ); // insert into working memory like any other fact

    // insert other facts, etc here, then fire rules

    kieSession.fireAllRules();

    // ... etc
  }
}

我已经使用Spring完成了这样的依赖注入。不需要您尚未使用的其他依赖项。

© www.soinside.com 2019 - 2024. All rights reserved.