简体   繁体   English

咨询Spring MVC HTTP消息转换器

[英]Advice spring mvc http message converter

I am trying to advice spring http message converter but, I can't get it to work. 我正在尝试建议spring http消息转换器,但是,我无法使其正常工作。

@Pointcut("within(org.springframework.http.converter.xml.MarshallingHttpMessageConverter)")
public void converterPointcut() {
}

@Pointcut("execution(* *(..))")
public void converterMethodPointcut() {
}

@Around("converterPointcut() && converterMethodPointcut()")
public Object aroundConverter(ProceedingJoinPoint iJoinPoint) {
    Object aProceed = null;
    try {
        aProceed = iJoinPoint.proceed();
    } catch (Throwable anException) {
        anException.printStackTrace();
    }
    return aProceed;
}

Anything wrong here? 这里有什么问题吗?

a) using within , you are only advising the Methods of the MarshallingHttpMessageConverter class, are you sure that's what you want? a)使用within ,你只提供咨询意见的方法MarshallingHttpMessageConverter类,你确定这就是你想要什么?

b) to weave a library class you need to either set up load time weaving or run the spring jars through the aspectj compiler (ouch, don't do that) . b)要编织一个库类,您需要设置 加载时间编织 或通过Aspectj编译器运行spring jars(哎呀,不要那样做) Do you have load time weaving set up? 您是否设置了加载时间编织?

c) define can't get it to work: what happens, what doesn't happen? c)定义无法使其正常工作:会发生什么,不会发生什么?


Update: I think you are trying to solve the wrong problem. 更新:我认为您正在尝试解决错误的问题。 Don't use AspectJ, just extend the class ( none of the methods are final ) and register the extended class as HttpMessageConverter 不要使用AspectJ,只需扩展类( 所有方法都不是final )并将扩展的类注册为HttpMessageConverter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM