[英]AspectJ with Spring Security
我有這個注釋和方面類
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AroundHere {
}
@Aspect
@Component
public class SomeAspect {
@Around("@annotation(com.annotation.AroundHere)")
public Object redirectIfNotEditingStatus(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("hi");
return pjp.proceed();
}
}
我想在一些帶有@AroundHere
注釋的方法上打印“hi”。 它在服務層上工作正常,但不在控制器上工作。 我懷疑是Spring Security,因為它會掃描所有控制器組件。
如何讓它們在控制器上工作?
很可能它不適合你,因為aop:aspectj-autoproxy
是在一個應用程序上下文中定義的,而你的控制器在不同的應用程序上下文中。 通常, BeanFactoryProcessors
(在aop:aspectj-autoproxy
位於上下文中時執行實際工作)僅對定義它們的容器中的bean起作用。 因此,例如,如果您在根應用程序上下文中定義了aspectj-autoproxy
,它將不會對*-servlet.xml
上下文中定義的bean執行操作。
您可以在此處找到與此主題相關的相關文檔:
BeanPostProcessors的范圍是每個容器。 這僅在您使用容器層次結構時才有意義。 如果在一個容器中定義BeanPostProcessor,它將只對該容器中的bean進行后處理。 換句話說,在一個容器中定義的bean不會被另一個容器中定義的BeanPostProcessor進行后處理,即使兩個容器都是同一層次結構的一部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.