“aop:aspectj-autoproxy”和“mvc:annotation-driven”都存在于 XML 配置中。 这两个类都被定义为同一 XML 中的 bean。
在本地/开发环境中使用 Spring 3.2.3.RELEASE 和 Google App Engine 1.8.1。
我的切入点不执行。
我的建议。在用 @Aspect 注释的类中声明。
@Component
@Aspect
public class RequestLimiter {
private MemcacheService cache = MemcacheServiceFactory.getMemcacheService();
@Pointcut("within(@pcs.annotations.LimitRequests com.zdware.pcs.controllers.PingCollectorController)")
public void methodRequestLimited(){}
@Around("methodRequestLimited() && args(req,limitRequests)")
public Object requestGateWay(ProceedingJoinPoint jp, HttpServletRequest req,LimitRequests limitRequests) throws Throwable {
// do stuff
}
}
我用来在控制器层测试的方法。
@Controller
public class PingCollectorController {
@RequestMapping(value="/test")
@LimitRequests(requestTimeLimit = 1, functionName = "Test")
public String test(){
return "test"; // this will return me to a jsp that doesnt exist, but my advice is still not executing.
}
}
最佳答案
CGLIB 是否在类路径中?需要生成代理(因为您的 Controller 没有实现接口(interface),所以 spring 无法使用更简单的 JDK 代理)。
关于java - 为什么我的建议/切入点根本不运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17416507/