com.drools.solon.config.DroolsAutoConfiguration Maven / Gradle / Ivy
package com.drools.solon.config;
import org.noear.solon.Utils;
import org.noear.solon.annotation.*;
import com.drools.solon.KieSchedule;
import com.drools.solon.KieTemplate;
import static com.drools.solon.common.Constants.LISTENER_CLOSE;
import java.util.Objects;
/**
* @author Karas
* @date 2019/9/26
* @since 1.0.0
*/
@Configuration
public class DroolsAutoConfiguration {
@Init
public void init() {
System.setProperty("file.encoding", "UTF8");
}
@Bean
@Condition(onMissingBean = KieTemplate.class)
KieTemplate kieTemplate(@Inject("${solon.drools}") DroolsProperties droolsProperties) {
String path = droolsProperties.getPath();
if(Utils.isBlank(path)){
throw new IllegalArgumentException("Please set base path(spring.drools.path = xxx).");
}
KieTemplate kieTemplate = new KieTemplate();
kieTemplate.setPath(droolsProperties.getPath());
kieTemplate.setMode(droolsProperties.getMode());
String autoUpdate = droolsProperties.getAutoUpdate();
if (Objects.equals(LISTENER_CLOSE, autoUpdate)) {
// 关闭自动更新
kieTemplate.setUpdate(999999L);
} else {
// 启用自动更新
kieTemplate.setUpdate(droolsProperties.getUpdate());
}
kieTemplate.setListener(droolsProperties.getListener());
kieTemplate.setVerify(droolsProperties.getVerify());
String charset = droolsProperties.getCharset();
if (Utils.isNotBlank(charset)) {
kieTemplate.setCharset(charset);
}
return kieTemplate;
}
@Bean
@Condition(onMissingBean = KieSchedule.class)
public KieSchedule kieSchedule(KieTemplate kieTemplate) {
KieSchedule kieSchedule = new KieSchedule(kieTemplate);
kieSchedule.execute();
return kieSchedule;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy