1. 程式人生 > >struts2學習中遇到的坑之 嚴重: Dispatcher initialization failed錯誤

struts2學習中遇到的坑之 嚴重: Dispatcher initialization failed錯誤

錯誤提示:
Unable to load configuration. - interceptor-ref - file:/E:/eclipse/hibernate/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/hibernate_crm/WEB-INF/classes/struts.xml:14:46
提示xml檔案14行有錯誤

嚴重: Dispatcher initialization failed
Unable to load configuration. - interceptor-ref - file:/E:/eclipse/hibernate/.metadata
/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/hibernate_crm/WEB-INF/classes/struts.xml:14:46 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967) at org.apache.struts
2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479) at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
.init(StrutsPrepareAndExecuteFilter.java:57) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485) 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:745) Caused by: Unable to find interceptor class referenced by ref-name loginInterceptor - interceptor-ref - file:/E:/eclipse/hibernate/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/hibernate_crm/WEB-INF/classes/struts.xml:14:46 at com.opensymphony.xwork2.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:63) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.lookupInterceptorReference(XmlConfigurationProvider.java:1114) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptorStack(XmlConfigurationProvider.java:932) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptorStacks(XmlConfigurationProvider.java:945) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptors(XmlConfigurationProvider.java:968) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:537) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295) at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) ... 17 more 七月 01, 2017 12:23:41 下午 org.apache.catalina.core.StandardContext filterStart 嚴重: Exception starting filter struts2 Unable to load configuration. - interceptor-ref - file:/E:/eclipse/hibernate/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/hibernate_crm/WEB-INF/classes/struts.xml:14:46 at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:493) at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485) 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:745) Caused by: Unable to load configuration. - interceptor-ref - file:/E:/eclipse/hibernate/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/hibernate_crm/WEB-INF/classes/struts.xml:14:46 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479) ... 14 more Caused by: Unable to find interceptor class referenced by ref-name loginInterceptor - interceptor-ref - file:/E:/eclipse/hibernate/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/hibernate_crm/WEB-INF/classes/struts.xml:14:46 at com.opensymphony.xwork2.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:63) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.lookupInterceptorReference(XmlConfigurationProvider.java:1114) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptorStack(XmlConfigurationProvider.java:932) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptorStacks(XmlConfigurationProvider.java:945) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptors(XmlConfigurationProvider.java:968) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:537) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295) at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) ... 17 more

我找了很久,最後才發現

<interceptors>
        <!-- 註冊攔截器 -->
        <interceptor name="loginInter" class="hibernate.web.interceptor.LoginInterceptor"></interceptor>
            <!-- 註冊攔截器棧 -->
        <interceptor-stack name="myStack">
            <interceptor-ref name="loginInterceptor">
                <param name="excludeMethods">login</param>
            </interceptor-ref>
            <interceptor-ref name="defaultStack"></interceptor-ref>
        </interceptor-stack>
</interceptors>

自己註冊的攔截器的名字 即“loginInter”必須和註冊攔截器棧中的引用的攔截器名字 即“loginInterceptor”一致。
如下修改即可

<interceptors>
        <!-- 註冊攔截器 -->
        <interceptor name="(loginInterceptor)" class="hibernate.web.interceptor.LoginInterceptor"></interceptor>
            <!-- 註冊攔截器棧 -->
        <interceptor-stack name="myStack">
            <interceptor-ref name="(loginInterceptor)">
                <param name="excludeMethods">login</param>
            </interceptor-ref>
            <interceptor-ref name="defaultStack"></interceptor-ref>
        </interceptor-stack>
</interceptors>

括號部分為修改部分