시간을 기록하는 데 사용되는 사용자 지정 인터셉터를 정의하지만 작동하지 않습니다. 나는 새로운 XML 파일 정의내 사용자 지정 인터셉터가 작동하지 않는 이유
public class TimeConsumedInterceptor extends AbstractInterceptor
{
/*
* {@inheritDoc}
*/
@Override
public String intercept(ActionInvocation invocation) throws Exception
{
long start = System.currentTimeMillis();
String result = invocation.invoke();
long end = System.currentTimeMillis();
System.out.println("time consumed: " + (end - start));
return result;
}
}
: 여기 내 사용자 정의 인터셉터 코드 ECS-default.xml에을 (직접적 패키지 src
아래)
<struts>
<include file="struts-default.xml"></include>
<!-- ecs-default package is abstract -->
<package name="ecs-default" extends="struts-default" abstract="true">
<interceptors>
<interceptor name="ecsTimer" class="com.nader.interceptor.TimeConsumedInterceptor"></interceptor>
<interceptor-stack name="ecsStack">
<interceptor-ref name="ecsTimer"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
<!-- default stack used for ecs-default package -->
<default-interceptor-ref name="ecsStack"></default-interceptor-ref>
<global-results>
<result name="error">error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error" />
</global-exception-mappings>
</package>
</struts>
및 struts.xml 파일 :
<struts>
<include file="ecs-default.xml"></include>
<!-- define two empty package,/and /manager, extends ecs-default package -->
<package name="default" namespace="/" extends="ecs-default">
</package>
<package name="manager" namespace="/manager" extends="ecs-default">
</package>
</struts>
내가 com.opensymphony.xwork2.DefaultActionInvocation
클래스 List<InterceptorMapping> interceptorList = new ArrayList<InterceptorMapping>(proxy.getConfig().getInterceptors());
에서 코드를 디버깅, proxy.getConfig().getInterceptors()
는 STR에 정의 defaultStack의 18 인터셉터를 반환 uts-default.xml, 내 ecsTimer 인터셉터가 없습니다. 왜? 제 구성에 문제가 있습니까? 감사.
내가 스트럿 주석을 사용, 난 그냥 당신이 @ParentPackage (값 = "JSON-기본") @namespace (값 = "/ 관리자") @InterceptorRef (값 = "ecsStack") 공개'고 말했다 않는 클래스 UserSearchAction이 ActionSupport'를 확장합니다. '... 이제 오류를보고합니다. ref-name ecsStack - [unknown location]이 참조하는 인터셉터 클래스를 찾을 수 없습니다. 그래서 그것을 해결하는 방법? 이 인터셉터 클래스는 확실히 존재합니다. – hiway
해결 방법은 http://stackoverflow.com/questions/8600148/how-to-link-custom-interceptor-using-annotation을 참조하십시오. struts2 주석은 XML 구성보다 복잡하다고 생각합니다. 매우 감사합니다. – hiway