我手头有一个自定义拦截器,我希望它使用注释与 Action 类相关联。我已经使用 struts.xml 中声明的拦截器引用添加了拦截器引用,但出现异常,
"SEVERE: Exception starting filter Struts2
Unable to load configuration. - [unknown location]"
我的 Action 类如下,
@Action(value = "/login", results = {
@Result(name = "success", location = "/Welcome.jsp"),
@Result(name = "error", location = "/Login.jsp") },
interceptorRefs = {
@InterceptorRef("defaultStack"),
@InterceptorRef("myLogging")}
)
public String validateCredentials() {
if (this.userName.equals("Raj") && this.password.equals("aspire")) {
return "success";
} else {
// addActionError(getText("error.login"));
return "error";
}
}
我的 struts.xml 如下,
<package name="default" extends="struts-default" namespace="/">
<interceptors>
<interceptor name="myLogging" class="org.struts.hello.MyLoggingInterceptor"/>
</interceptors>
</package>
错误堆栈:
SEVERE: Exception starting filter Struts2
Unable to load configuration. - [unknown location]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3838)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4488)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: Unable to find interceptor class referenced by ref-name loggingStack - [unknown location]
at com.opensymphony.xwork2.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:52)
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:676)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:493)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:278)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:52)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:200)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
... 21 more
Dec 22, 2011 3:30:22 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Dec 22, 2011 3:30:22 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/StrutsAnnotation] startup failed due to previous errors
最佳答案
我没有太多使用带或不带 struts2 的注释的 exp,但我相信您正在使用 convention-plugin 。这是他们对您的问题所说的快速截图。
有关更多详细信息,请参阅那里的文档
convention-plugin