Spring-Drools Integration: Referenced file (ki

2019-04-11 11:08发布

问题:

I'm trying to use drools with Spring. Spring version 4.01 Drools/Kie version 6.0.1

My kie-context.xml has the following error (in Eclipse):

Referenced file contains errors (http://drools.org/schema/kie-spring.xsd). For more information, right click on the message in the Problems View and select "Show Details..."

kie-context.xml: (imported in applicationContext.xml)

    <?xml version="1.0" encoding="UTF-8"?>
<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://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <kie:kmodule id="ng-rule-server">
        <kie:kbase name="kbase1" packages="org.drools.server">
            <kie:ksession name="ksession1" type="stateless" />
        </kie:kbase>
    </kie:kmodule>

    <bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor" />
</beans>

Relevant pom.xml:

        <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>

<kie.version>6.0.1.Final</kie.version>            
<drools.version>6.0.1.Final</drools.version>

Details:

Can anybody see what's wrong with my set up?

回答1:

I skipped that error pointing xsi:schemaLocation directly to github address.

You can find it here: https://raw.github.com/droolsjbpm/droolsjbpm-integration/master/kie-spring/src/main/resources/org/kie/spring/kie-spring-6.0.0.xsd

In kie-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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.xsd
    http://drools.org/schema/kie-spring
    https://raw.github.com/droolsjbpm/droolsjbpm-integration/master/kie-spring/src/main/resources/org/kie/spring/kie-spring-6.0.0.xsd">

<kie:kmodule id="sample_module">
    <kie:kbase name="kbase1">
        <kie:ksession name="ksession1" />
    </kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>
</beans>

Is not the good way, but works. Hope this helps.



回答2:

The right location can also be referred to by using the classpath : URL handler

xmlns:kie="http://drools.org/schema/kie-spring" xsi:schemaLocation="http://drools.org/schema/kie-spring classpath:org/kie/spring/kie-spring-6.0.0.xsd"



回答3:

I had the same error in eclipse with Spring 3.2.8 and Drools 6.0.0.Final. And during application startup it used to fail with below error:

Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'Drools - JBoss Community'.

After using kie-spring dependency, above problem got resolved.

    <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-spring</artifactId>
        <version>${org.drools.version}</version>
    </dependency>