我正在学习 JavaBrains 教程,完成类(class)后,Tomcat 说:
SEVERE: Exception starting filter struts2
另外:
Caused by: Unable to load configuration. - action - file:/Users/jasonrodriguez/Java/apache-tomcat-7.0.47/wtpwebapps/TutorialFinder/WEB-INF/classes/struts.xml:8:83
Caused by: Action class [org.koushik.javabrains.action.TutorialAction] not found - action - file:/Users/jasonrodriguez/Java/apache-tomcat-7.0.47/wtpwebapps/TutorialFinder/WEB-INF/classes/struts.xml:8:83
我回去检查,我的 web.xml
具有正确的过滤器映射:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>TutorialFinder</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
我的 struts.xml
有命名空间、操作名称和类属性:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/tutorials" extends="struts-default">
<action name="getTutorial" class="org.koushik.javabrains.action.TutorialAction">
<result name="success">/success.jsp</result>
<result name="failure">/error.jsp</result>
</action>
</package>
</struts>
我的库构建路径是正确的,但是当我运行 Tomcat 时,它告诉我该资源不可用,并且由于我是新手,我不知道如何对其进行故障排除,因为我的项目中的任何地方都没有红色 x 标记。我想也许某个地方有一个文件不合适,但它看起来很直接:
也许一双新的眼睛可以发现我错过的东西。我昨天在本教程中遇到了类似的问题,解决方案是在我的操作标记中提供类路径上存在的类引用。然而,据我所知,该标签看起来已经是正确的。我的目标是获得并执行我创建的业务服务。
最佳答案
您写了错误的包名称:org.kouhsik.javabrains.action.TutorialAction
应该是org.koushik.javabrains.action.TutorialAction
。可能这只是一个拼写错误,或者您使用了重构工具来更改包名称。无论哪种方式,您都应该重新使用它,或者在配置中使用对类标记中的操作的正确引用。另一种方法是使用约定插件并通过注释创建配置。在这种情况下,您无需编写对操作或方法的引用,因为您可以将注释放在要配置的类或方法的右侧。
关于java - 无法在 Java 中加载配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20036082/