s2sh全注解拦截器的问题我是用的s2sh全注解构建的,所有的Action的配置都构建在了action类的注解上了,所以struts.xml都给省了,现在我想构建一个拦截器也要用全注解方式做.搞了很久,求高手解答

解决方案 »

  1.   

    楼主说的struts.xml都省了,说是省了,但还是省不了的。最起码struts包中就有很多类似的配置文件。既然整合了spring,可以用spring的aop技术实现拦截器的功能。
      

  2.   

    在struts的包里还是有缺省的配置的,包括默认的拦截器配置
    所以,用注解方式配置拦截器的时候,要手动把默认拦截器加上去,否则默认拦截器不会被调用
      

  3.   

    可以用代码展现下吗?在action上注解是这样配置吗?@InterceptorRef( value="CKinterceptor")
    public class UserAction extends ActionSupport {在拦截器上又是怎样配置呢
    public class CKinterceptor extends AbstractInterceptor {
      

  4.   

    aop也一样可以采用注解的的方式和配置文件配置的方式。
    注解的话,用到@Aspect ,定义切入点@Pointcut,设置前置通知@Before,后置通知@AfterReturning等。
    楼主找下资料看吧。也很容易,在帖子里看回帖,不是很系统。
    比如:http://www.redsaga.com/spring_ref/2.0/html/aop.html
      

  5.   

    aop 很适合做权限,某种意义上说就是为这样的需求用的。
    楼主自动看吧。觉得可以就看看相关资料吧。
      

  6.   

    这样是可以的!!
    也就是人们常说的ssh零配置(我认为应该是1配置,因为至少得保留applicationContext.xml这个文件),
    其它的配置文件(比如struts.xml,hibernate映射文件)之类的全部删掉.
    全部用注解替代,这样的项目是最精简的,效率也是最高的.
    lz说的完全可行!!
      

  7.   


    官方网的例子
    http://struts.apache.org/2.3.4/docs/convention-plugin.html#ConventionPlugin-InterceptorRefannotationInterceptors can be specified at the method level, using the Action annotation or at the class level using the InterceptorRefs annotation. Interceptors specified at the class level will be applied to all actions defined on that class. In the following example:package com.example.actions;import com.opensymphony.xwork2.ActionSupport;
    import org.apache.struts2.convention.annotation.Action;
    import org.apache.struts2.convention.annotation.Actions;@InterceptorRefs({
        @InterceptorRef("interceptor-1"),
        @InterceptorRef("defaultStack")
    })
    public class HelloWorld extends ActionSupport {
      @Action(value="action1", interceptorRefs=@InterceptorRef("validation"))
      public String execute() {
        return SUCCESS;
      }  @Action(value="action2")
      public String doSomething() {
        return SUCCESS;
      }
    }The following interceptors will be applied to "action1": interceptor-1, all interceptors from defaultStack, validation.
    All interceptors from defaultStack will be applied to "action2".If you get errors like "Unable to find interceptor class referenced by ref-name XYZ". This means that the package where Convention is placing your actions, does not extend the package where the interceptor is defined. To fix this problem either 1)Use @ParentPackage annotation(or struts.convention.default.parent.package) passing the name of the package that defines the interceptor, or 2) Create a package in XML that extends the package that defines the interceptor, and use @ParentPackage(or struts.convention.default.parent.package) to point to it.struts2的所谓的零配置前提是使用Convention Plugin插件
    按官方网的例子,注解只需要在action方定义,拦截器方不用定义