drools spring config的问题

在开发中经常会用到spring, 现在的各种框架于spring的结合也非常好。

但是并没有注意configure的时候一些格式问题,今天就碰到了格式带来的困扰。

<drools:kagent id="kagent1" kbase="kbase1" new-instance="false">
    <drools:resources>                
        <drools:resource type="DRL" source="classpath:Sample.drl" />
    </drools:resources>
</drools:kagent>

<drools:kagent id="kagent1" kbase="kbase1" new-instance="false">
    <drools:resources>
        <drools:resource type="DRL" source="classpath:Sample.drl" />
    </drools:resources>
</drools:kagent>

上面的两个configure看上去一模一样,但是用第一个的时候就会有错误

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 17 in XML document from class path resource [drools-services.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.3: Element 'drools:resources' cannot have character [children], because the type's content type is element-only.

后来跟官方的configure文件对比,发现<drools:resources>后面有一些空格,就是我用红色标出的部分。去掉这些空格之后就没有问题了。这些是从word里面copy出来的。可能带有一些word的格式信息,被xds检查的时候报的错误。如果是直接用space加的空格是不会有问题的。

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                           http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring-1.3.0.xsd

原文地址:https://www.cnblogs.com/scarlettxu/p/3412428.html