Alexander Alexander - 4 months ago 57
Java Question

Drools not working correctly with Spring Boot

I want to use Drools with Spring Boot for Bean Validation but I have narrowed the problem down to this few lines of code:

The Main-Class

public class App {

public static void main(String[] args) {
//, args);

public static void check() {
// load up the knowledge base
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-rules");
Patient patient = new Patient("Hans", "Mueller");

is an Entity with just an id, firstname and lastname with getter and setter.

The kmodule.xml

<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="">
<kbase name="rules" packages="rules">
<ksession name="ksession-rules"/>

and two rules

package com.sample

import com.sample.Patient;

rule "Test"
eval(1 == 1)
System.out.println("This rule is always fired");

rule "Patient"
exists Patient()
System.out.println("Patient found");

When not calling, args)
(like above) everything works fine:

15:50:12.730 [main] DEBUG org.drools.core.impl.KnowledgeBaseImpl - Starting Engine in PHREAK mode
15:50:12.820 [main] DEBUG org.drools.core.common.DefaultAgenda - State was INACTIVE is nw FIRING_ALL_RULES
15:50:12.821 [main] DEBUG org.drools.core.common.DefaultAgenda - Fire Loop
This rule is always fired
15:50:12.827 [main] DEBUG org.drools.core.common.DefaultAgenda - Fire Loop
Patient found
15:50:12.827 [main] DEBUG org.drools.core.common.DefaultAgenda - Fire Loop
15:50:12.827 [main] DEBUG org.drools.core.common.DefaultAgenda - State was FIRING_ALL_RULES is nw HALTING
15:50:12.827 [main] DEBUG org.drools.core.common.DefaultAgenda - State was HALTING is nw INACTIVE

However, when I add, args)
to the main, only one rule is fired:

This rule is always fired

Not even the logging of
is visible anymore.

I have no idea whats going wrong? I expect the same output in both situations. Is SpringBoot doing something in the background?


For everybody that has the same problem and reads my question:

I haven't solved it directly but the problem has something to do with netbeans. Everything works fine when starting the application via command line. So this is the way to go.