0 Replies Latest reply on May 27, 2016 9:18 PM by duanjunwei

    It seems a bug about the kie-spring: <kie:import><kie:releaseId> of Drools 6.4.0 final.

    duanjunwei

      Dear Drools team, Drools workbench team

       

      I use the Drools 6.4.0 to construct rule business service to my J2EE application, and the Drools workbench provides a remote repository to manage the rule resources. I finished the integration about Spring and drools6.4.0 using kie-spring, it is very nice working for me.

       

      but, when I test the auto loading rule resource from remote workbench , I met the problem as below:

      I created one project named 'sample' in the remote Workbench Server. and created 2 kbases ( named 'sample_kbase' and 'price_kbase') in this project. My J2EE application using spring3 and the spring -xml is:

      <?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:jee="http://www.springframework.org/schema/jee"
        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
        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://www.springframework.org/schema/tx 
                           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
                           http://www.springframework.org/schema/jee 
                           http://www.springframework.org/schema/jee/spring-jee-3.0.xsd 
                           http://www.springframework.org/schema/context 
                           http://www.springframework.org/schema/context/spring-context-3.0.xsd 
                           http://www.springframework.org/schema/aop 
                           http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
                           http://www.springframework.org/schema/task 
                           http://www.springframework.org/schema/task/spring-task.xsd 
                           http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd">
      
        <kie:import releaseId-ref="ks-releaseId" enableScanner="true" scannerInterval="300000"/>
        <kie:releaseId id="ks-releaseId" groupId="com.genscript"
               artifactId="sample" version="LATEST"/> 
      
      
        <bean id="kiePostProcessor"
        class="org.kie.spring.annotations.KModuleAnnotationPostProcessor" /> 
      
      </beans>
      

       

      I started the j2ee tomcat server , and I got the exception:

      java.lang.IllegalStateException: Could not register object [org.kie.scanner.KieRepositoryScannerImpl@32121ce3] under bean name 'ks-releaseId#scanner': there is already object [org.kie.scanner.KieRepositoryScannerImpl@32121ce3] bound
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.registerSingleton(DefaultSingletonBeanRegistry.java:124)
        at org.kie.spring.factorybeans.KieImportFactoryBean.registerKieBases(KieImportFactoryBean.java:127)
        at org.kie.spring.factorybeans.KieImportFactoryBean.postProcessBeanFactory(KieImportFactoryBean.java:106)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:640)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:405)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
      

       

      So, I try to debug the Drools Kie-Spring Source Code, and I found that in the class file: KieImportFactoryBean.java , the method registerKieBases throw the exception, because I have 2 Kbases defined in the Workbench Project. This method will traverse the Kbases and duplicate exec the configurableListableBeanFactory.registerSingleton(releaseIdName+"#scanner", kieScanner);

          protected void registerKieBases(ConfigurableListableBeanFactory configurableListableBeanFactory) {
              for (String kieBaseName : kContainer.getKieBaseNames()) {
                  if ( scannerEnabled ) {
                      registerKieBeanDef((BeanDefinitionRegistry) configurableListableBeanFactory, kieBaseName);                
                      configurableListableBeanFactory.registerSingleton(releaseIdName+"#scanner", kieScanner);
                  } else {
                      KieBase kieBase = kContainer.getKieBase(kieBaseName);
                      configurableListableBeanFactory.registerSingleton(kieBaseName, kieBase);
                  }
                  registerKieSessions(kieBaseName, configurableListableBeanFactory);
              }
          }
      

       

      And then, I try to modify the source code to the below:

          protected void registerKieBases(ConfigurableListableBeanFactory configurableListableBeanFactory) {
              for (String kieBaseName : kContainer.getKieBaseNames()) {
                  if ( scannerEnabled ) {
                      registerKieBeanDef((BeanDefinitionRegistry) configurableListableBeanFactory, kieBaseName);
                      
                      if( !configurableListableBeanFactory.containsSingleton(releaseIdName+"#scanner") ){
                          configurableListableBeanFactory.registerSingleton(releaseIdName+"#scanner", kieScanner);
                      }
                  } else {
                      KieBase kieBase = kContainer.getKieBase(kieBaseName);
                      configurableListableBeanFactory.registerSingleton(kieBaseName, kieBase);
                  }
                  registerKieSessions(kieBaseName, configurableListableBeanFactory);
              }
          }
      

       

      It seems running well, please Drools Team help to confirm if this is a bug about Drools 6.4.0, or My using is wrong , if i was wrong, please help to guide me to solve the problem, thanks very much.

       

      my email address: 273305351@qq.com

       

      best reagrds.