我知道这个问题有很多线索,我试图通过所有的答案,但到目前为止没有任何工作。我的代码不会抛出任何错误,网页已启动并正常工作,但控件永远不会出现方面方法。这是我的Controller类:
@Controller
public class MyController {
@RequestMapping(value = "/welcome", method = RequestMethod.GET)
@RequiresAuthenticatedUser
public ModelAndView execute(final HttpServletRequest request) {
System.out.println("welcome!");
// generates model and view
return mav;
}
}
方面 -
@Aspect
@Component
public class RequiresAuthenticatedUserAspect {
@Around("@annotation(com.mypkg.RequiresAuthenticatedUser)")
public void validateUser(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
Object[] args = proceedingJoinPoint.getArgs();
throw new Exception("Unauthorized user");
}
}
应用程序上下文 -
<!-- Enable AspectJ style of Spring AOP -->
<aop:aspectj-autoproxy proxy-target-class="false">
<aop:include name="requiresAuthenticatedUser" />
</aop:aspectj-autoproxy>
请帮忙。
答案 0 :(得分:0)
所以我认为你应该检查你的dispatcher-servlert.xml(可能是其他名字),你应该扫描包中的RequiresAuthenticatedUserAspect并注意你也应该扫描组件注释。