我是在为 @InterceptorRef 示例 编写代码时了解到此功能的。我必须在 struts.xml 文件中声明拦截器定义,而我想使用带有注释的拦截器。第一次尝试时,它失败并出现以下错误:
Unable to load configuration. - [unknown location] at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490) Caused by: Unable to find interceptor class referenced by ref-name customStack - [unknown location] at com.opensymphony.xwork2.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:63) at org.apache.struts2.convention.DefaultInterceptorMapBuilder.buildInterceptorList(DefaultInterceptorMapBuilder.java:95) at org.apache.struts2.convention.DefaultInterceptorMapBuilder.build(DefaultInterceptorMapBuilder.java:86) at org.apache.struts2.convention.DefaultInterceptorMapBuilder.build(DefaultInterceptorMapBuilder.java:64)
默认情况下,Convention 插件使用它自己的包 convention-default,它不包含您在 struts.xml 中定义的包。这意味着约定放置您的操作的包不会扩展定义拦截器的包。
要改变你有两个选择:
@ParentPackage
注解的使用例如
<struts> <package name="default" namespace="/" extends="struts-default"> <interceptors> <interceptor name="demoCustomInterceptor" class="com.cundage.struts2.example.web.DemoCustomInterceptor" /> <interceptor-stack name="customStack"> <interceptor-ref name="demoCustomInterceptor"/> <interceptor-ref name="defaultStack" /> </interceptor-stack> </interceptors> </package> <constant name="struts.convention.result.path" value="/WEB-INF/jsp/" /> <constant name="struts.devMode" value="true" /> <constant name="struts.action.extension" value="action," /> <constant name="struts.custom.i18n.resources" value="test" /> <constant name="struts.convention.default.parent.package" value="default"/> </struts>
这将解决问题。
快乐学习!!
地址:https://www.cundage.com/article/solved-unable-to-find-interceptor-class-referenced-by-ref-name.html