Red Hat Bugzilla – Bug 996560
Cannot initialize kmodule in beans.xml during deployment
Last modified: 2014-08-06 16:07:07 EDT
Description of problem:
I tried to create my own web application with kie-spring integration but during deployment it throws following exception:
Caused by: java.lang.IllegalArgumentException: Could not find a KModule (defaultClasspathKContainer is null).
at org.kie.spring.KieObjectsResolver.resolveKContainer(KieObjectsResolver.java:76) [kie-spring-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
at org.kie.spring.KieObjectsResolver.resolveKBase(KieObjectsResolver.java:50) [kie-spring-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
The reason is on line 46 here https://github.com/droolsjbpm/droolsjbpm-integration/blob/master/kie-spring/src/main/java/org/kie/spring/KieObjectsResolver.java#L46 , the defaultClasspathKContainer inicialization code is commented.
However this fix is not enough to deploy the app.
The next exception I receive is:
Caused by: java.lang.NullPointerException
at org.drools.compiler.kie.builder.impl.KieContainerImpl.createKieBase(KieContainerImpl.java:199) [drools-compiler-6.0.0-SNAPSHOT.jar:6.0.0-SNAPSHOT]
at org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:167) [drools-compiler-6.0.0-SNAPSHOT.jar:6.0.0-SNAPSHOT]
at org.kie.spring.KieObjectsResolver.resolveKBase(KieObjectsResolver.java:51) [kie-spring-6.0.0-SNAPSHOT.jar:6.0.0-SNAPSHOT]
I think that the kBaseModel is null on line 199 in the KieContainerImpl https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/main/java/org/drools/compiler/kie/builder/impl/KieContainerImpl.java#L199
The spring context is created by default in the web application by org.springframework.web.context.ContextLoaderListener, so there is no initialization of post processor beans such as KModuleBeanFactoryPostProcessor. So it uses the default container.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Clone https://github.com/ibek/droolsjbpm-integration/tree/6.0.x/
2. Build drools-camel-server-example
3. Run Tests
4. See following exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ksession1': Cannot resolve reference to bean 'kbase1' while setting bean property 'kBase'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kbase1': Invocation of init method failed; nested exception is java.lang.NullPointerException
FYI tests in kie-spring works just because they use different way how to create spring context. So, you can try that it works when you uncomment lines in CxfRSClientServerTest like below:
//ReleaseId releaseId = new ReleaseIdImpl("sample-group","test-spring","001");
//URL configFileURL = CxfRsClientServerTest.class.getResource("/beans.xml");
//ApplicationContext springContext = InternalKieSpringUtils.getSpringContext(releaseId,configFileURL);
I cloned your repo and tried what you did. The only missing bit in your migration attempt is the registration of the kiePostProcessor in the spring context, i.e. adding this:
<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>
to the beans.xml file should fix your problem.
If you can confirm it fixes your problem (or even if it doesn't and then requires further investigation) it would be great if you could send a proper pull request so I could merge the migration of drools-camel-server-example to the new kie-spring and kie-camel modules on the master branch.
thank you, the added bean helped and the test passed. However I wasn't successful with the deployment. Now, I receive NPE when the KModuleFactory is trying to get POM properties file:
at org.drools.compiler.kie.builder.impl.ClasspathKieProject.getPomProperties(ClasspathKieProject.java:240) [drools-compiler-6.0.0-SNAPSHOT.jar:6.0.0-SNAPSHOT]
at org.kie.spring.KModuleBeanFactoryPostProcessor.postProcessBeanFactory(KModuleBeanFactoryPostProcessor.java:84) [kie-spring-6.0.0-SNAPSHOT.jar:6.0.0-SNAPSHOT]
I think it's because it searches the pom.properties at wrong location. The root path is /content/drools-camel-server-example-6.0.0-SNAPSHOT.war/WEB-INF/classes/ but the pom.properties is in /content/drools-camel-server-example-6.0.0-SNAPSHOT.war/META-INF/maven/org.drools/drools-camel-server-example/pom.properties.
I read this information from the following warning in the server log:
12:58:01,639 WARN [org.drools.compiler.kie.builder.impl.ClasspathKieProject] (ServerService Thread Pool -- 82) Unable to load pom.properties tried recursing down from/content/drools-camel-server-example-6.0.0-SNAPSHOT.war/WEB-INF/classes/
Of course, I will create the pull request but first I want to do some cleaning of source code because I use the example for experimenting now.
In fact, the pom.xml cannot be found at the location. I tried to copy the pom.xml and pom.properties into classes just to check whether it will help and it really did, I successfully deployed the web app. So after all there is just the issue with pom files.
I believe this last issue is strictly related (if not the same) with this one found by Marek:
I'll try to fix that one first and hopefully this should also solve your problem. I'll keep you updated.
Yep, it seems they are same. I noticed that the workaround works only when the war is deployed as a folder like business central. So I recommend to consider both options, the war archive and folder.
Verified in BPMS 6.0.0.ER3