Drools doesn't work with spring-boot-devtools

徘徊边缘 提交于 2019-12-08 08:59:58

问题


When we have spring-boot-devtools on pom.xml the drools rules dont work. There are no error but the drools rules dont get fired at all. After excluding the spring-boot-devtools the drools rule start working.


回答1:


Really strange problem indeed. As far as I can tell, there are 2 issues here:

  1. Apparently, the KieFileSystem doesn't play well with org.springframework.boot.devtools.restart.classloader.RestartClassLoader. Even if I tried passing the DRL as a String, it didn't take it.
  2. Even if I managed to get a populated KieBase using a kmodule.xml file, the rules were still not firing. My guess is that the classloader at some points changes the definition of the classes, so when you insert a Product object, its class is no longer the same as the Product class that is being used by the DRL. Another possibility is that there are multiple classloaders in play. Take a look at this question and at this document.

Unfortunately, I was not able to find a way to make it work. I hope the information I've provided helps you.




回答2:


There's a documented issue about a classloading problem while using spring-boot devtools together with drools: DROOLS-1540

As specified in spring-boot reference documentation you can add jars to the devtools "reloading" classloader as a workaround.

META-INF/spring-devtools.properties

restart.include.drools-core=/drools-core-7.0.0.Final.jar
restart.include.drools-compiler=/drools-compiler-7.0.0.Final.jar
restart.include.kie-api=/kie-api-7.0.0.Final.jar
restart.include.kie-ci=/kie-ci-7.0.0.Final.jar
restart.include.kie-internal=/kie-internal-7.0.0.Final.jar

Be careful to use YOUR exacts jar and eventually add other libraries directly referenced in your rules files.


(for moderator) flgged Drools rule does't working in Spring Boot Controller but working in Junit Test as duplicated of this question and removed the answer on that post



来源:https://stackoverflow.com/questions/55373809/drools-doesnt-work-with-spring-boot-devtools

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!