gpt4 book ai didi

包上的 Drools DRL 文件无法读取

转载 作者:行者123 更新时间:2023-12-02 08:37:47 24 4
gpt4 key购买 nike

我是 drools 的新手,我无法访问包内的 DRL 文件。和我想的一样。我的项目规则层次结构是这样的

enter image description here

我尝试使用以下代码访问 DRL 文件:

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "neu/als/KnowledgeLevel", getClass() ), ResourceType.DRL );
KnowledgeBuilderErrors errors = kbuilder.getErrors();

if( errors.size() > 0 )
{
for( KnowledgeBuilderError error : errors )
{
System.err.println( error );
}
throw new IllegalArgumentException( "Could not parse knowledge." );
}

KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
return kbase;

这是导致错误的原因:

java.lang.RuntimeException: Unable to get LastModified for ClasspathResource
at org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:204)
at org.drools.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.drools.compiler.DrlParser.parse(DrlParser.java:145)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:477)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:466)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:694)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
at com.neu.als.thesis.units.InferenceEngine.readKnowledgeBase(InferenceEngine.java:52)
at com.neu.als.thesis.web.controllers.FLTController.evaluateFLT(FLTController.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:444)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:432)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:946)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:848)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:822)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: 'neu/als/KnowledgeLevel.drl' cannot be opened because it does not exist
at org.drools.io.impl.ClassPathResource.getURL(ClassPathResource.java:165)
at org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:177)
... 40 more

我做错了什么?

更新:

这是我的 web.xml

<servlet>
<servlet-name>ThesisProject</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ThesisProject</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ThesisProject-servlet.xml</param-value>
</context-param>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

和我的bean配置

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="com.neu.als.thesis.web.controllers" />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>

</beans>

添加了一些配置

最佳答案

您的知识库是使用“neu/als/KnowledgeLevel”作为类路径构建的,而根据您的目录结构,正确的路径应该是“com/neu/als/KnowledgeLevel”。

我不希望 src/main/rules 位于项目类路径中,这也可能影响这一点。

我通常将我的规则保存在 src/main/resources 下,以便 Maven 将它们构建到类路径中。

关于包上的 Drools DRL 文件无法读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19554361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com