spring - 是否使用基于注释的AOP修改 Controller 响应?

标签 spring grails groovy aop spring-aop

我正在尝试通过AOP将 header 添加到 Controller 响应中,但是我不确定如何访问 Controller 或 Controller 响应。

我该怎么做呢?

这是我当前的注释:

@Retention(RetentionPolicy.RUNTIME)
@Target([ElementType.METHOD, ElementType.TYPE, ElementType.FIELD])
public @interface NoCaching {
}

这是我当前的方面:
@Aspect
@Component("noCachingAspect")
class NoCachingAspect {

    @Pointcut("@annotation(com.grailsrocks.cacheheaders.NoCaching)")
    public void nameDoesntMatter() {
    }

    @Before("com.grailsrocks.cacheheaders.NoCachingAspect.nameDoesntMatter()")
    public void beforeMethod(JoinPoint joinPoint) throws Throwable {
        println 'hellowoeijf'
    }
}

这是我使用注释的方式:
@NoCaching
    def annotations(){
        println 'bar'
    }

如何访问注释所针对的 Controller 以修改响应对象?

最佳答案

我前不久写了一篇有关此的博客文章,请参阅http://burtbeckwith.com/blog/?p=80

关于spring - 是否使用基于注释的AOP修改 Controller 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10124660/

相关文章:

groovy - 在整个 grails 应用程序中保留 url 参数

spring - 如何创建 Redis 条件 Bean?

java - 使用 Java DSL 从文件轮询 - 添加 Files.inboundAdapter 时出现编译错误

java - spring数据查询dsl如何添加order by?

hibernate - 如何将此SQL转换为Grails Gorm条件查询

java - Java 8 Lambda 表达式的 Groovy 等价物

java - 如何将两个对象传递给同一个Spring Controller 表单提交?

grails - Grails SubFlow不呈现其 View 页面并返回HTTP 404

grails - Grails中的条件动态查找器

javascript - 将返回的 Json 响应与发布的响应进行比较