How does kie-spring find and incorporate DRL files (packages) into a kie:kbase bean?

1,703 views
Skip to first unread message

Ken Siprell

unread,
Mar 12, 2015, 8:13:15 AM3/12/15
to drools...@googlegroups.com

How does kie-spring find and incorporate DRL files (packages) into a kie:kbase bean?


I understand the convention with kmodule.xml and src/main/resources/path/to/drl/files, which I’ve gotten to work without any trouble. Does kie:spring do a similar scan automatically?


If the questions don’t make sense, here’s the background.

 

I’m trying to integrate kie-spring into two Grails plugins (https://github.com/kensiprell/grails-drools, https://github.com/kensiprell/grails3-drools). Grails is a web application framework based on Spring, and Grails 3 (milestone release only) is based on Spring Boot, so kie-spring seemed like a good fit. I’m a hobby developer, and my limited Drools experience began about two months ago when I started working on the first plugin.

 

The plugins work except that I cannot get the kbase beans to recognize the rule packages; they’re always null.  I’ve gone through the Drools documentation and a couple of books, and I’m sure I’m missing something simple.  Unfortunately, almost all of the Spring examples I’ve seen on GitHub aren’t using kie-spring.

 

The Drools Spring documentation (chapter 11) led me to believe that all I needed to do is to import the beans (example config below) and have the DRL files on the classpath, which I do with a Gradle task (https://github.com/kensiprell/grails3-drools/blob/master/buildSrc/src/main/groovy/grails/plugin/drools/DroolsGradlePlugin.groovy#L14-L47). The beans all seem to be working fine except for the lack of rules associated with the kbase beans.

 

<?xml version='1.0' encoding='utf-8'?>

<beans xmlns='http://www.springframework.org/schema/beans' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:kie='http://drools.org/schema/kie-spring' xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd'>

 
<kie:kmodule id='defaultKieModule'>

   
<kie:kbase name='applicationKieBase' default='false' packages='rules.application'>

     
<kie:ksession name='applicationStatefulSession' default='false' type='stateful' />

     
<kie:ksession name='applicationStatelessSession' default='false' type='stateless' />

   
</kie:kbase>

   
<kie:kbase name='ticketKieBase' default='false' packages='rules.ticket'>

     
<kie:ksession name='ticketStatefulSession' default='false' type='stateful' />

     
<kie:ksession name='ticketStatelessSession' default='false' type='stateless' />

   
</kie:kbase>

 
</kie:kmodule>

 
<bean id='kiePostProcessor' class='org.kie.spring.KModuleBeanFactoryPostProcessor' />

</beans>

 

Although my current project’s state isn’t reflected in the repo, I tried moving my rules source directory to /src/main/resources/ and also added the proper package name to the DRL files, but that didn’t help. This repo (https://github.com/vinodkiran/kie-springmvc) looks like a good match, but it hasn’t helped me either. It doesn’t look like he’s doing anything special to associate the rules packages with his kbase bean.

 

The only thing that stands out to me is that my Drools beans are imported (https://github.com/kensiprell/grails3-drools/blob/master/src/main/groovy/grails/plugin/drools/DroolsGrailsPlugin.groovy#L30) late in the application startup cycle.

 

Thanks for any tips!

 

Ken

Vinod Kiran

unread,
Mar 12, 2015, 6:19:09 PM3/12/15
to drools...@googlegroups.com
kie-spring does not do anything special, it is but a thin layer on kmodule.xml. The scanning is done by the same manner as kmodule.xml

Can you double check if the DRLs are available src/main/resources/rules/application, src/main/resources/rules/ticket ?

Ken Siprell

unread,
Mar 15, 2015, 7:41:08 AM3/15/15
to drools...@googlegroups.com
Thanks for your help, Vinod.

I found your Spring Boot example (https://github.com/vinodkiran/kie-spring-boot) yesterday, and after running mvn package I saw that the DRL file along with its parent directory was copied to target/main/classes/.

Grails 3 uses Gradle as the build tool, so I configured my plugin to copy the rules files and their parent directories to build/main/classes/, which worked. I thought I’d tried this already, so I wasted some time trying other techniques. Plus, since I’m not using maven, it doesn’t matter where the source DRL files are located. I had to put them directly under src/ to keep the Grails build tasks from copying them into the build/ directory, i.e. under build/main/resources.

Thanks again,
Ken

On 12.03.2015, at 23:19, Vinod Kiran <vinod...@gmail.com> wrote:

kie-spring does not do anything special, it is but a thin layer on kmodule.xml. The scanning is done by the same manner as kmodule.xml

Can you double check if the DRLs are available src/main/resources/rules/application, src/main/resources/rules/ticket ?

On Thursday, March 12, 2015 at 7:13:15 AM UTC-5, Ken Siprell wrote:

How does kie-spring find and incorporate DRL files (packages) into a kie:kbase bean?


I understand the convention with kmodule.xml and src/main/resources/path/to/drl/files, which I’ve gotten to work without any trouble. Does kie:spring do a similar scan automatically?


If the questions don’t make sense, here’s the background.

 

I’m trying to integrate kie-spring into two Grails plugins (https://github.com/kensiprell/grails-drools,https://github.com/kensiprell/grails3-drools). Grails is a web application framework based on Spring, and Grails 3 (milestone release only) is based on Spring Boot, so kie-spring seemed like a good fit. I’m a hobby developer, and my limited Drools experience began about two months ago when I started working on the first plugin.

 

The plugins work except that I cannot get the kbase beans to recognize the rule packages; they’re always null.  I’ve gone through the Drools documentation and a couple of books, and I’m sure I’m missing something simple.  Unfortunately, almost all of the Spring examples I’ve seen on GitHub aren’t using kie-spring. 

 

The Drools Spring documentation (chapter 11) led me to believe that all I needed to do is to import the beans (example config below) and have the DRL files on the classpath, which I do with a Gradle task (https://github.com/kensiprell/grails3-drools/blob/master/buildSrc/src/main/groovy/grails/plugin/drools/DroolsGradlePlugin.groovy#L14-L47). The beans all seem to be working fine except for the lack of rules associated with the kbase beans.

 
<?xml version='1.0' encoding='utf-8'?>



  <kie:kmodule id='defaultKieModule'> 

    <kie:kbase name='applicationKieBase' default='false'packages='rules.application'> 

      <kie:ksession name='applicationStatefulSession' default='false'type='stateful' /> 

      <kie:ksession name='applicationStatelessSession' default='false'type='stateless' /> 

    </kie:kbase> 

    <kie:kbase name='ticketKieBase' default='false' packages='rules.ticket'> 

      <kie:ksession name='ticketStatefulSession' default='false'type='stateful' /> 

      <kie:ksession name='ticketStatelessSession' default='false'type='stateless' /> 

    </kie:kbase> 

  </kie:kmodule> 

  <bean id='kiePostProcessor' class='org.kie.spring.KModuleBeanFactoryPostProcessor' /> 

</beans> 

 

Although my current project’s state isn’t reflected in the repo, I tried moving my rules source directory to /src/main/resources/ and also added the proper package name to the DRL files, but that didn’t help. This repo (https://github.com/vinodkiran/kie-springmvc) looks like a good match, but it hasn’t helped me either. It doesn’t look like he’s doing anything special to associate the rules packages with his kbase bean.

 

The only thing that stands out to me is that my Drools beans are imported (https://github.com/kensiprell/grails3-drools/blob/master/src/main/groovy/grails/plugin/drools/DroolsGrailsPlugin.groovy#L30) late in the application startup cycle.

 

Thanks for any tips!

 

Ken


-- 
You received this message because you are subscribed to a topic in the Google Groups "Drools Setup" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/drools-setup/PpK7Yacyez8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to drools-setup...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-setup/c9beebb8-c7a7-4889-92b6-a74cd8432387%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages