Java 无法在 Struts 中加载配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18738054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 10:36:20  来源:igfitidea点击:

Unable to load Configuration in Struts

javaeclipsespringhibernatestruts2

提问by Prasanna

I'm trying to implement STRUTS SPRING AND HIBERNATE INTEGRATION ON ONLINE EXAMINATION. while running the project in Eclipse Kepler using apache tomcat 7.0.42, it throws me the following error

我正在尝试在在线考试中实施 STRUTS SPRING 和 HIBERNATE 集成。使用 apache tomcat 7.0.42 在 Eclipse Kepler 中运行项目时,它抛出以下错误

**HTTP Status 404 - /OnlineExam/registration.jsp**
**Description:**The requested resource is not available.

In Console log, following things appear,

在控制台日志中,出现以下内容,

    SEVERE: Exception starting filter struts2
Unable to load configuration. - action - file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtpwebapps/iSAS/WEB-INF/classes/struts.xml:16:73
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:431)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:724)
Caused by: Unable to load configuration. - action - file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtpwebapps/iSAS/WEB-INF/classes/struts.xml:16:73
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418)
    ... 14 more
Caused by: Error building results for action userRegistration in namespace  - action - file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtpwebapps/iSAS/WEB-INF/classes/struts.xml:16:73
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:367)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:468)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:264)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:193)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
    ... 16 more
Caused by: There is no result type defined for type 'tiles' mapped with name 'SUCCESS'.  Did you mean 'tiles'? - result - file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtpwebapps/iSAS/WEB-INF/classes/struts.xml:17:40
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java:621)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:365)
    ... 21 more

struts.xml

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
    <constant name="struts.ui.theme" value="simple" />
    <constant name="struts.devMode" value="true" />

    <package name="default" extends="struts-default">       
        <result-types>
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
        </result-types>

        <action name="userRegistration" method="{1}" class="userRegistration">
            <result name="SUCCESS" type="tiles">isas.user.registration</result>
            <result name="ERROR" type="tiles">isas.errorPage</result>
            <result name="input" type="tiles">isas.user.registration</result>
        </action>

    </package>
</struts>

Please Help me Friends. I don't know why that appears. Anyway thanks in Advance...!!!

请帮助我的朋友。我不知道为什么会出现这种情况。无论如何,在此先感谢...!!!

采纳答案by Ha Nguyen

I think you are missing the "struts2-spring-plugin-2.1.6.jar" file, please check it in your classpath

我认为您缺少“struts2-spring-plugin-2.1.6.jar”文件,请在您的类路径中检查它

回答by L Petre

i got the same error, however , adding that jar did not fix my problem.

但是,我遇到了同样的错误,添加该 jar 并没有解决我的问题。

as the error states: Unable to load configuration. - action - file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtpwebapps/iSAS/WEB-INF/classes/struts.xml:16:73

如错误所述:Unable to load configuration. - action - file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtpwebapps/iSAS/WEB-INF/classes/struts.xml:16:73

there is a problem in your struts.xml at line 16, which is

在第 16 行的 struts.xml 中存在问题,即

<action name="userRegistration"method="{1}"class="userRegistration">

<action name="userRegistration"方法="{1}"class="userRegistration">

struts tries to load the method named {1} from the class userRegistration. probably that method does not exist, as it is an invalid java name. i am not sure if struts accepts such a notation like {1} to refer to the first method in a class (probably not), but in my case, that was the problem: in struts.xml, in the action tag, i was refering a method whose name was misspelled, so struts was trying to find a nonexistent method, which caused this error - unable to load configuration.

struts 尝试从类 userRegistration 加载名为 {1} 的方法。可能该方法不存在,因为它是无效的 Java 名称。我不确定 struts 是否接受像 {1} 这样的符号来引用类中的第一个方法(可能不是),但在我的情况下,这就是问题所在:在 struts.xml 中,在 action 标记中,我是引用名称拼写错误的方法,因此 struts 试图找到一个不存在的方法,这导致了此错误 - 无法加载配置。

回答by amit kaushik

Have fixed the problem. Hope the solution would be useful for some one else:

已经解决了问题。希望该解决方案对其他人有用:

struts.xml file must be present under WebContent - WEB-INF - classes - struts.xml when using eclipse

使用 eclipse 时,struts.xml 文件必须存在于 WebContent - WEB-INF - classes - struts.xml 下

The mistake i did was when ever i did a clean project it used to delete my files under classes folder, so do make sure that this particular file is present.

我犯的错误是当我做一个干净的项目时,它用来删除类文件夹下的文件,因此请确保存在此特定文件。