0

struts2에서 annotation을 사용하여 인터셉터를 사용하여 요청 및 응답을 처리하여 일부 사전 및 사후 작업을 수행 할 수있었습니다.Struts2에서 Annotation과 Spring과 Convention Plugin을 함께 사용하기

하지만 실제로 변경할 수없는 플러그인 플러그인이있는 스트럿츠 2를 사용했습니다. 내 프레임 워크에는 스프링이 포함되어 있습니다.

하지만 문제는 인터셉터를 주석으로 사용하려고 할 때마다 응용 프로그램이 시작될 때 예외가 발생한다는 것입니다.

SEVERE: Exception starting filter struts2 
Unable to load configuration. - [unknown location] 
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:483) 
.... 
Caused by: Unable to load configuration. - [unknown location] 
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58) 
..... 
Caused by: Unable to find interceptor class referenced by ref-name mylogging - [unknown location] 

내 코드 구조는 매우 간단합니다 :

@InterceptorRefs({ 
    @InterceptorRef("mylogging") 
}) 
    public class LoginAction implements ModelDriven{ 
..... 
    @Action(value="/login",results={@Result(name="success",location="/jsp/successPage.jsp"), 
       @Result(name="login",location="/jsp/userLogin.jsp")}) 
     public String execute() { 
.... 

Struts.xml :

Action 클래스처럼 보인다

<struts> 
    <constant name="struts.devMode" value="true" /> 
    <constant name="struts.ui.theme" value="simple" /> 
    <constant name="struts.enable.SlashesInActionNames" value="true" /> 
    <constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/> 
    <package name="default" namespace="" extends="struts-default"> 


    <interceptors> 
      <interceptor name="mylogging" 
       class="com.lab.interceptor.LoggingInterceptor"> 
      </interceptor> 
      <interceptor-stack name="loggingStack"> 
       <interceptor-ref name="mylogging" /> 
       <interceptor-ref name="defaultStack" /> 
      </interceptor-stack> 
     </interceptors> 
    </package> 
</struts> 

내 배치 기술자 본체 (web.xml에) :

<filter> 
    <filter-name>struts2</filter-name> 
    <filter-class> 
     org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 
    </filter-class> 
    <init-param> 
      <param-name>actionPackages</param-name> 
      <param-value>com.lab.actions</param-value> 
     </init-param> 
    </filter> 


    <filter-mapping> 

    <filter-name>struts2</filter-name> 
    <url-pattern>*.action</url-pattern> 
    </filter-mapping> 
    <context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>/WEB-INF/classes/resources/config/SpringBeans.xml</param-value> 
</context-param> 

    <listener> 
    <listener-class> 
     org.springframework.web.context.ContextLoaderListener 
    </listener-class> 

    </listener> 

이제는 그 예외를 던지고있는 이유를 알아내는 데 도움이 될 것입니다. ModelDriven 구현을 제 조치에서 제거해야한다고 생각하지 않기 때문입니다. 기본적으로 사전

+1

경우 당신의 행동이''디폴트''패키지에 있다고 선언합니까? –

+0

@DaveNewton 나는 당신을 얻지 못했지만, user2607985

+1

패키지를 정의하지만 그것이 지정하지 않으면 당신의 행동이 불가사의하게 나타날 곳이 아닌 것 같아요. 그것이 행동이 속한 곳입니다. –

답변

2

에서

덕분 협약 플러그인은 struts.xml에 정의 된 패키지를 포함하지 않는 자신의 패키지 convention-default를 사용합니다. 두 가지 옵션을 가지고 변경하려면, 모두 워드 ​​프로세서 [1]에 설명 :

  • 또는 struts.xml에서 <constant name="struts.convention.default.parent.package" value="default"/>을 정의

    • 사용 @ParentPackage 주석

    [1] http://struts.apache.org/development/2.x/docs/convention-plugin.html#ConventionPlugin-ParentPackageannotation

  • 관련 문제