I have a situation. I am testing in junit with .drl files using the
kie-spring.
The DRL files are found/scanned only when they are co-located in the src/test/resources folder and not in the src/main/resources/folder.
I even moved the drl files to a
separate jar project/file into a src/main/resources folder along with
the kie-spring .xml files. Still no luck!
I get a WARN : No files found for KieBase kbase1, searching folder ...
How can I do?
Spring config file :
<import resource="applicationPropertiesContextTest.xml" />
<import resource="dependenciesInjectionContextTest.xml" />
<import resource="classpath*:droolsContext.xml" />
droolsContext.xml:
<kie:kmodule id="mykmodule">
<kie:kbase name="kbase1" default="true" packages="rules" >
<kie:ksession name="ksession" default="true" type="stateless" />
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor" class="org.kie.spring.annotations.KModuleAnnotationPostProcessor"/>
My droolsContext.xml is load but drl not found.
After test I want to package this jar with DRL in a war and I'll have the same problem.
Think you for response.
def doWithSpring = {
try {
importBeans("drools-context.xml")
} catch (e) {
log.debug(e)
log.error "grails-app/conf/drools-context.xml does not exist. Try 'grails create-drools-config' or 'grails create-drools-context'."
}
// If the application is running in a container such as Tomcat, Jetty, etc. webInfClasses should return something like:
// /Users/Ken/Library/tomcat/webapps/grails-drools-sample-1.1.0/WEB-INF/classes
File webInfClasses = application.parentContext?.getResource('WEB-INF/classes')?.file
String configFilePath
if (webInfClasses?.exists()) {
// Use canonicalPath in case we're running on Windows
configFilePath = configFilePath = new File(webInfClasses.path).canonicalPath
} else {
// This returns something like the line below if Grails is running in development or test mode:
// /Users/Ken/Development/Plugins/grails-drools-sample/src/resources
String userDir = System.getProperty("user.dir")
configFilePath = new File("$userDir/src/resources").canonicalPath
}
URL configFileURL = new File(configFilePath).toURI().toURL()
// This Grails DSL might look confusing, but it's creating a bean named "kiePostProcessor" using this constructor:
// https://github.com/droolsjbpm/droolsjbpm-integration/blob/master/kie-spring/src/main/java/org/kie/spring/KModuleBeanFactoryPostProcessor.java#L79
kiePostProcessor(KModuleBeanFactoryPostProcessor, configFileURL, configFilePath) {}
}
public class MyKModuleBeanFactoryPostProcessorFactory {
public KModuleBeanFactoryPostProcessor get() throws IOException {
URL resource = getClass().getResource("WEB-INF/classes");
String configFilePath;
if (resource != null) {
File webInfClasses = new File(resource.toString());
configFilePath = webInfClasses.getCanonicalPath();
} else {
String userDir = System.getProperty("user.dir");
configFilePath = new File(userDir + "/src/main/resources").getCanonicalPath();
}
URL configFileURL = new File(configFilePath).toURI().toURL();
return new KModuleBeanFactoryPostProcessor(configFileURL, configFilePath);
}
}
<bean id="myKModuleBeanFactoryPostProcessorFactory" class="com.x.x.MyKModuleBeanFactoryPostProcessorFactory " />
<bean id="kiePostProcessor" factory-bean="myKModuleBeanFactoryPostProcessorFactory" factory-method="get" />