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.