Hello,
I experience a problem autowiring my KieSession object into my Controller field in Spring.
I read the Spring integration configuration part of Drools documentation and edited my Spring
configuration as adviced. However on deploying I receive one and the same well know exception:
"org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.kie.api.runtime.KieSession] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.kie.api.cdi.KSession(name=, value=ksession-rules)}"
My application's web.xml defines my spring configuration entries as follows:
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
......
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/beans.xml,
/WEB-INF/security.xml,
/WEB-INF/entityManager.xml
</param-value>
</context-param>
As guided by Drools documentation I entered the following Drools configuration in my spring configuration (I try to put the bean both in mvc-dispatcher-servlet.xml configuration and in beans.xml the result is the same).
<!-- KieSession - Drools support -->
<kie:kmodule id="spring_module">
<kie:kbase name="rules" packages="com.my.sample.drools.rulespackage">
<kie:ksession name="ksession-rules" type="stateless">
</kie:ksession>
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>
<!-- Drools' configuration ends here! -->
I have this package
"com.my.sample.drools.rulespackage" with a simple and tested rule in it.
In my Controller class I am trying to autowire the KieSession bean to a field as follows:
@Controller
@RequestMapping(value = "/")
public class BaseController extends AbstractController {
private static final Logger log = Logger.getLogger(BaseController.class);
@Autowired
@KSession("ksession-rules")
KieSession mySession;
.............
}
I tryed with @Inject instead of spring's @Autowire, the result is the same.
I am using the following Drools dependencies with their versions:
drools-core - 6.0.0.FINAL; drools-compiler - 6.0.0.FINAL; kie-spring - 6.0.0.FINAL; (I am trying to keep it simple as my first integration try.)
The spring version that I am using is 3.2.4.RELEASE.
I debugged
KModuleBeanFactoryPostProcessor and I can clearly see that an object tree with KieModuleModelImpl, KieBaseModelImpl, KieSessionModelImpl,
with the corresponding details that I entered in the configuration above (packages, name, type, etc.) is created!. However it seems that a KieSession bean is not registered
spring's container.
What I do wrong? Can anyone please help?
Thanks in advance!
Best Regards,
Milen