Spring 4.0 & Drools 6.0.1 Integration issue
by kmansoor
Hi All- I'm trying to use Drools in a Spring 4 applications. Trying to inject
a StatelessSession in a Spring bean:
@Service
public class RulesServiceImpl implements RulesService {
@Inject()
private StatelessKieSession kStatelessSession;
...
}
This results in:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [org.kie.api.runtime.StatelessKieSession] found
for dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency. Dependency annotations:
{(a)javax.inject.Inject()}
pom.xml is as follows:
<kie.version>6.0.1.Final</kie.version>
<drools.version>6.0.1.Final</drools.version>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>${kie.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-internal</artifactId>
<version>${kie.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-spring</artifactId>
<version>${kie.version}</version>
</dependency>
and applicationContext.xml:
<kie:kmodule id="kmodule1">
<kie:kbase name="kbase1" packages="rules">
<kie:ksession name="ksession1" type="stateless" />
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor"
class="org.kie.spring.KModuleBeanFactoryPostProcessor" />
I also tried the other route:
@PostConstruct
public void setUp() {
KieServices kieServices = KieServices.Factory.get();
KieContainer kContainer = kieServices.getKieClasspathContainer();
kStatelessSession = kContainer.newStatelessKieSession("ksession1");
}
This results in NullPointerException:
Caused by: java.lang.NullPointerException
at
org.drools.compiler.kie.builder.impl.KieContainerImpl.newStatelessKieSession(KieContainerImpl.java:444)
at
org.drools.compiler.kie.builder.impl.KieContainerImpl.newStatelessKieSession(KieContainerImpl.java:435)
at
ca.utoronto.med.dc.webcv.service.RulesServiceImpl.setUp(RulesServiceImpl.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)
at
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)
at
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
... 23 more
I do see the following in the console:
2014-02-10 20:05:06,263 DEBUG
org.drools.compiler.kie.builder.impl.ClasspathKieProject.getPomProperties(210):
- Found and used pom.properties
\work\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\dcwebcv\META-INF\maven\ca.utoronto.med.dc\dcwebcv\pom.properties
releaseId == ca.utoronto.med.dc:dcwebcv:1.0-SNAPSHOT
2014-02-10 20:05:06,407 INFO
org.drools.compiler.kie.builder.impl.KieRepositoryImpl.addKieModule(72): -
KieModule was added:FileKieModule[
ReleaseId=ca.utoronto.med.dc:dcwebcv:1.0-SNAPSHOTfile=\work\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\dcwebcv\WEB-INF\classes]
Any pointer will be highly appreciated.
--
View this message in context: http://drools.46999.n3.nabble.com/Spring-4-0-Drools-6-0-1-Integration-iss...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 9 months
[MVEL BUG] MVEL Parsing error
by alexandrebhr
Hi,
I found a MVEL bug :
When I want to compile a specific expression with MVEL, a
NullPointerException is thrown.
Test Case (Java Language) :
String expression = "5 + 1/10 * (VAR - 5)";
MVEL.compileExpression(expression);
When I launch this test, I get an error :
java.lang.NullPointerException
at
org.mvel2.MVELInterpretedRuntime.parse(MVELInterpretedRuntime.java:47)
at org.mvel2.MVEL.eval(MVEL.java:408)
at org.mvel2.ast.Substatement.getReducedValue(Substatement.java:48)
at
org.mvel2.compiler.AbstractParser.arithmeticFunctionReduction(AbstractParser.java:2479)
at
org.mvel2.compiler.ExpressionCompiler.compileReduce(ExpressionCompiler.java:318)
at
org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:172)
at
org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:62)
at org.mvel2.MVEL.compileExpression(MVEL.java:810)
at org.mvel2.MVEL.compileExpression(MVEL.java:820)
at org.mvel2.MVEL.compileExpression(MVEL.java:723)
...
I get this error in rare case with this syntax but with different one, it
works.
Expressions which work :
5 + 1+10 * (VAR - 5)
5 + 1-10 * (VAR - 5)
5 + (1/10) * (VAR - 5)
5 + (VAR - 5) * 1/10
Expressions which not work :
5 + 1/10 * (VAR - 5)
5 + 1*10 * (VAR - 5)
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/MVEL-BUG-MVEL-Parsing-error-tp4028939.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 9 months
Embedded sub-process in drools rule flow
by Sanjay Mj
Hi all,
Can anyone please tell me whether it is possible to design nested blocks in
rule flow. I know that using sub-process, we can embed different rule
tasks, but my rule flow file is getting bulkier by the day and I wanted to
know if i can have a few rules in a sub-process, but the rule tasks
executed by the sub-process should not be visible in the uppermost layer.
DOuble clicking on that should take me inside the sub-process and show the
rules executed by it. Also if it is not possible to have such an operation
with the build in blocks in drools rule flow, can anyone tell me how i can
have a custom made block which has that functionality. I have designed
custom blocks having simple properties, but i have no idea how this should
be done. Hope to get an answer here.
Regards sanjay
10 years, 9 months
Getting started
by vvicky72
I am a newbie to both Drools and Maven. I was asked to research how we can
build brms using drools. This is what I am trying
1) Setup a guided decision table using drools workbench.
This worked without much issues. I deployed the project ( pnd-1.1.pom
<http://drools.46999.n3.nabble.com/file/n4028927/pnd-1.1.pom> )pom.xml
attached.
2) Setup a drools project in ecplise to execute the rule. To do this
a) I installed the Maven plugin in eclipse.
b) I copied the pom.xml create above to my drools project (Not sure if this
was the right thing to do).
c) I then ran Maven install using eclipse. That got the jar file pnd-1.1.jar
(kie wb project created using workbench).
d) I copied the following code to execute the rules
<http://drools.46999.n3.nabble.com/file/n4028927/DroolsTestClient.jpg>
*My first problem was that it would not find the bean (Data Model) that is
in the pnd-1.1.jar.* For the sake of moving forward, I recreated that class
in my drools project on eclipse.
This is how my project looks.
<http://drools.46999.n3.nabble.com/file/n4028927/Droolsproject.jpg>
*Now when I run it I get the error java.lang.RuntimeException: Cannot find
KieModule: com.yrc.ops:pnd:1.1*
I am obviously missing something. But after reading several posts and
tutorials I am still unable to solve it. Please shed some light and help me
out.
Thanks.
--
View this message in context: http://drools.46999.n3.nabble.com/Getting-started-tp4028927.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 9 months
Not able to detect how to correct ERR 102
by ankit3j
Below is a sample DSLR code I am trying out. Now I am getting error in "when"
block. After hours of trying to search for a solution I have not yet been
able to detect the error.
package com.sample
import com.sample.*;
//expander sample.dsl
rule "hello rule"
when
There is a "$customer" with first name "David" // This is
where the error is
then
Greet Customer
end
[ERR 102] Mismatched input "is" in rule "hello rule"
Any idea whats wrong with this line??
--
View this message in context: http://drools.46999.n3.nabble.com/Not-able-to-detect-how-to-correct-ERR-1...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 9 months
Performance of rules in Drools
by Seb Geek
Hello,
I have a list of very similar rules executed in Drools and some performance
problems appear ... I want some advices to choose between two "direction"
in order to correct them ...
First the context :
I have to execute always the same check but with different level or
"parameters".
For example,
- in the first demand (rule for our client) i have to count and retrieve
the list all Article that have a family code equals to 'A', 'B' or 'C' and
execute the then clause only if there is 3 elements in the filtered list.
- in the second demand (rule for our client) i have to count and retrieve
the list all Article that have a family code equals to 'B' or 'C' and
execute the then clause only if there is 4 elements in the filtered list
and so on ...
The number of different group of parameter values and the values of theses
parameters will change over time ...
The question is : is it more efficient to implement a lot of different
rules, each with their parameter in the code OR is it more efficient to
implement only one rule with an additional object as a drools fact
containing different parameter's values ?
Thanks for your help
Sébastien
10 years, 9 months
6.0.1.F How to set Maven repo used by KieScanner?
by SrjTx
I am doing the following, but no rules ever fire. I suspect the maven repo
location is not right -and that no rules are getting loaded - how do I set
it?
I am using /root/.m2/repository
It would be the programmatic equivalent of
-Dorg.guvnor.m2repo.dir=/root/.m2/repository"
Also, how do you list the rules that are in the base? I see there is a
getRule(...), but no getRules.
kieServices = KieServices.Factory.get();
releaseId = kieServices.newReleaseId("com.xyz.policy", "cep",
"LATEST");
kieContainer = kieServices.newKieContainer(releaseId);
kieBase = kieContainer.newKieBase(config);
kieSession = kieBase.newKieSession();
kieSession.addEventListener((RuleRuntimeEventListener) this);
kieScanner = kieServices.newKieScanner(kieContainer);
kieScanner.start(10000L);
--
View this message in context: http://drools.46999.n3.nabble.com/6-0-1-F-How-to-set-Maven-repo-used-by-K...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 9 months
NullPointerException with kie-spring 6.0.1 and Spring 4.0
by Andrew Berman
Hello,
I'm trying to play around with Drool 6.0.1 integration with Spring (I'm
using spring-boot which includes spring 4.0). I've looked at the unit
tests written and have copied them pretty much exactly. When I start the
app, I consistently receive:
Caused by: org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class [org.kie.spring.KModuleBeanFactoryPostProcessor]:
Constructor threw exception; nested exception is
java.lang.NullPointerException
at
org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:164)
at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1069)
... 22 more
Caused by: java.lang.NullPointerException
at
org.kie.spring.KModuleBeanFactoryPostProcessor.initConfigFilePath(KModuleBeanFactoryPostProcessor.java:79)
at
org.kie.spring.KModuleBeanFactoryPostProcessor.<init>(KModuleBeanFactoryPostProcessor.java:64)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at
org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
When debugging the NPE comes from line 79,
getClass().getResource("/").getPath(), because getResource yields null.
Here is my spring context file:
<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-4.0.xsd
http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd
">
<kie:kmodule id="kmodule">
<kie:kbase name="kbase1" packages="rules.drools">
<kie:ksession name="ksession">
<kie:consoleLogger/>
</kie:ksession>
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor"
class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>
</beans>
Can someone help out?
Thanks!!
10 years, 9 months