droolskiespring-boot-devtools

Drools does not match my fact


I am new to drools and have defined two rules :

package com.mgaudin.sandbox.drools.rules;

import com.mgaudin.sandbox.drools.models.Lead;

rule "rule1"
    when
        l: Object()
    then
        System.out.println(l.getClass().getCanonicalName());
end

And

package com.mgaudin.sandbox.drools.rules;

import com.mgaudin.sandbox.drools.models.Lead;

rule "rule2"
    when
        Lead()
    then
        System.out.println("It's a match !");
end

When I insert a new com.mgaudin.sandbox.drools.models.Lead fact, the output is the following :

com.mgaudin.sandbox.drools.models.Lead

Therefore we can deduce that :

  1. The rules compiles properly
  2. The rules are executed
  3. The first rule matches with a fact of type "com.mgaudin.sandbox.drools.models.Lead"

So why is the rule "rule2" not matching ?

Thanks !


Solution

  • OK I found the answer and it's not related to Drools, it's related to Spring-boot-devtools !

    I don't know the exact mechanism but to enable fast hot reload (even if a method signature changes), spring-boot-devtools must mess with the JVM and proxify some objects, in my case, the fact. Because of this and the way Drools matches fact, the rule did not triggered.

    All I had to do was remove the maven dependency to spring-boot-devtools.