您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Spring Boot和Drools集成

Spring Boot和Drools集成

我尝试了同样的方法,最终为此制造了一个spring-boot-starter-drools,因为在那里没有任何工作可用。我没有使用XML-Configuration,因为最新的Spring配置仅与Java有关-我也建议您这样做。

@Configuration
public class DroolsAutoConfiguration {

private static final String RULES_PATH = "rules/";

@Bean
public KieFileSystem kieFileSystem() throws IOException {
KieFileSystem kieFileSystem = getKieServices().newKieFileSystem();
for (Resource file : getRuleFiles()) {
    kieFileSystem.write(ResourceFactory.newClassPathResource(RULES_PATH + file.getFilename(), "UTF-8"));
}        
return kieFileSystem;
}

private Resource[] getRuleFiles() throws IOException {
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
return resourcePatternResolver.getResources("classpath*:" + RULES_PATH + "**/*.*");
}

@Bean
public KieContainer kieContainer() throws IOException {
final KieRepository kieRepository = getKieServices().getRepository();

kieRepository.addKieModule(new KieModule() {
    public ReleaseId getReleaseId() {
        return kieRepository.getDefaultReleaseId();
    }
});

KieBuilder kieBuilder = getKieServices().newKieBuilder(kieFileSystem()); 
kieBuilder.buildAll();

return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId());
}

private KieServices getKieServices() {
return KieServices.Factory.get();
}

@Bean
public KieBase kieBase() throws IOException {
return kieContainer().getKieBase();
}

@Bean
public KieSession kieSession() throws IOException {
return kieContainer().newKieSession();
}

@Bean
public KModulebeanfactoryPostProcessor kiePostProcessor() {
return new KModulebeanfactoryPostProcessor();
}
}
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-spring</artifactId>
<version>${drools.version}</version>
<exclusions>
<exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
</exclusion>
<exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>

Java 2022/1/1 18:16:54 有521人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶