我正在使用Spring AOP来验证我的请求 我已经创建了注释,并在该注释被命中时调用了建议。
Aspect类:
@Aspect
public class BaseValidationAspect {
@Around(value = "execution(@com.pankanis.module.payval.aspect.BaseValidation * *(..))")
public Response validate(ProceedingJoinPoint joinPoint) {
System.out.println("Before");
try {
response = (Response)joinPoint.proceed();
} catch (Throwable e) {
}
System.out.println("After");
return response;
}
}
注释定义:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.TYPE})
public @interface BaseValidation {
}
服务类:
public class MessageBuilderImpl extends BaseMessageBuilder implements MessageBuilder {
@BaseValidation
public Response<Object> buildMessage(MessageHelper msg, String... args) {
Response<Object> resp = new Response<Object>();
//do something
return resp;
}
}
My Beans Xml配置:
<aop:aspectj-autoproxy />
<bean name="baseValidationAspect"
class="****.BaseValidationAspect">
//properties
</bean>
<bean id="messageBuilder" class="****.MessageBuilderImpl"
parent="baseMsgBuilder">
//properties
</bean>
当我在控制器方法上使用注释时,会调用建议。 但是在我的服务方法上,建议不会被调用。 这段代码有什么问题?