Use Spring AOP for permission verification, springaop

Source: Internet
Author: User

Use Spring AOP for permission verification, springaop

Before using Spring AOP, you must first introduce the corresponding package

<dependency>    <groupId>org.aspectj</groupId>    <artifactId>aspectjrt</artifactId>    <version>1.8.10</version></dependency><dependency>    <groupId>org.aspectj</groupId>    <artifactId>aspectjweaver</artifactId>    <version>1.8.10</version></dependency>

Then create the partition class

1 package com. homework. filter; 2 3 import org. aspectj. lang. proceedingJoinPoint; 4 import org. aspectj. lang. annotation. around; 5 import org. aspectj. lang. annotation. aspect; 6 import org. aspectj. lang. annotation. before; 7 import org. springframework. stereotype. component; 8 9/** 10 * Created by ytt on April /1/11. 11 */12 13 @ Aspect14 @ Component15 public class LoginCheckAspect {16 17 @ Around (value = "@ annotation (org. springframework. web. bind. annotation. requestMapping) ") 18 public Object checkUser (ProceedingJoinPoint pjp) throws Throwable {19 20 // obtain parameter 21 Object [] args = pjp. getArgs (); 22 System. out. println ("before entering the method"); 23 // allow 24 Object proceed = pjp. proceed (); 25 System. out. println ("after method execution"); 26 return proceed; 27} 28 29 @ Before ("execution (* com. homework. controller .. *. *(..)) ") 30 public void before () {31 System. out. println ("executed before method execution"); 32} 33}

In this way, the interception can be completed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.