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.struts2.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.(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.(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">loginparam>
            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">loginparam>
            interceptor-ref>
            <interceptor-ref name="defaultStack">interceptor-ref>
        interceptor-stack>
interceptors>

括号部分为修改部分

你可能感兴趣的:(java,EE)