@Secured annotations not working in AspectJ Mode with Autoproxy

后端 未结 2 2058
孤独总比滥情好
孤独总比滥情好 2020-12-10 09:25

I\'m trying to get my Spring MVC app to play nice with Spring @Secured annotations and AspectJ auto-proxying but it doesn\'t seem to be proxying or recognising my @Secured a

2条回答
  •  庸人自扰
    2020-12-10 10:16

    When using AOP with Spring you can choose between two implementations of AOP:

    • Spring AOP implementation doesn't require weaving, but it's only applicable to beans managed by Spring and have some limitations

    • AspectJ AOP implementation can work for all objects and doesn't have limitations of Spring AOP, but requires compile-time or load-time weaving

    mode="aspectj" tells Spring to use AspectJ for AOP implementation, therefore security aspect won't work without weaving in your case.

    The term "AspectJ auto-proxying" has nothing to do with using AspectJ as AOP implementation - it's a feature that allows you to use AspectJ API (rather than implementation) with Spring AOP.

    So, in your case you can use Spring AOP implementation, because controller is a Spring bean, therefore you should remove mode="aspectj". Also note that your controller should have no-arguments constructor - it's one of the limitations of Spring AOP.

提交回复
热议问题