【发布时间】:2017-09-25 16:29:44
【问题描述】:
我有以下实现:
public interface BusinessResource {
@RequiresAuthorization
public ResponseEnvelope getResource(ParamObj param);
}
和
@Component
public class BusinessResourceImpl implements BusinessResource {
@Autowired
public Response getResource(ParamObj param) {
return Response.ok().build();
}
}
和
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class AuthorizerAspect {
protected static final Logger LOGGER =
LoggerFactory.getLogger(AuthorizerAspect.class);
@Autowired
public AuthorizerAspect() {
LOGGER.info("Break point works here..." +
"so spring is creating the aspect as a component...");
}
@Around(value="@annotation(annotation)")
public Object intercept(ProceedingJoinPoint jp,
RequiresAuthorization annotation) throws Throwable {
LOGGER.info("BEGIN");
jp.proceed();
LOGGER.info("END");
}
}
使用 spring-boot-starter-aop 依赖项正确配置了 maven 依赖项。那么如果在 BusinessResource 接口的声明方法上使用了@RequiresAuthorization,AuthorizerAspect 不会拦截 getResource 方法,但是,如果我现在更改实现以在 BusinessResourceImpl 类中注释相同的方法,则会发生方面。
注意:使用接口级别的注解,甚至不会创建代理,而放置在实现级别的注解将为资源创建代理。
问题是:有没有办法建议只在界面上出现注释的对象?
【问题讨论】:
标签: aop aspectj spring-aop pointcut