• 启动Tomcat时报错:Unable to load configuration.


    这里记录一下使用注解实现SSH拦截器,启动Tomcat时报Unable to load configuration. - [unknown location]错的一种解决方法。

    下面是报错的详细信息:

    Unable to load configuration. - [unknown location]
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428)
    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: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:4830)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5510)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    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. - [unknown location]
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:371)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
    ... 14 more
    Caused by: Unable to find interceptor class referenced by ref-name loginCheck - [unknown location]
    at com.opensymphony.xwork2.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:63)
    at org.apache.struts2.convention.DefaultInterceptorMapBuilder.buildInterceptorList(DefaultInterceptorMapBuilder.java:99)
    at org.apache.struts2.convention.DefaultInterceptorMapBuilder.build(DefaultInterceptorMapBuilder.java:90)
    at org.apache.struts2.convention.DefaultInterceptorMapBuilder.build(DefaultInterceptorMapBuilder.java:74)
    at org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:861)
    at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:651)
    at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:336)
    at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:215)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)

    注意,我在信息里面highlight了一段信息,“loginCheck”是我使用注解时的名字,这里的错误并不是向网上其他人所报的jar包冲突,或者“file:/D:/apache-tomcat-6.0.29/webapps/DE/WEB-INF/classes/struts.xml:10:42”之类的错误,这里的错误明显指的是找不到相关信息,查证一下,发现是少了一个重要的注解,就是@ParentPackage("restrant"),这是声明拦截器所在的包的名字。先贴一下struts.xml配置文件出来,就明白了。

    <struts>
        <constant name="struts.i18n.encoding" value="utf-8"></constant>
        <package name="restrant" namespace="/" extends="struts-default">
        
           <!-- 配置拦截器AuthorityInterceptor -->
            <interceptors>
                <interceptor name="loginCheck" class="com.restrant.interceptor.AuthorityInterceptor" />
            
                <interceptor-stack name="auctionStack">  
                   <interceptor-ref name="defaultStack"/>  
                   <interceptor-ref name="loginCheck"/>  
               </interceptor-stack>  
            </interceptors>         
              
             <default-interceptor-ref name="auctionStack"/>   
        </package>
    </struts>

    配置文件里面的loginCheck拦截器是在名为“restrant”的package下面,所以在Action类里面如果要使用“loginCheck”拦截器的话,就是加上@ParentPackage("restrant")这句注解。

  • 相关阅读:
    PAT 1035. 插入与归并(25)
    PAT 1034. 有理数四则运算(20)
    PAT 1033. 旧键盘打字(20)
    PAT 1032. 挖掘机技术哪家强(20)
    PAT 1031. 查验身份证(15)
    PAT 1030. 完美数列(25)
    PAT 1029. 旧键盘(20)
    PAT 1028. 人口普查(20)
    PAT 1027. 打印沙漏(20)
    PAT 1026. 程序运行时间(15)
  • 原文地址:https://www.cnblogs.com/SysoCjs/p/9338822.html
Copyright © 2020-2023  润新知