forked from DerekYRC/mini-spring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.springframework.aop; | ||
|
||
import org.aopalliance.aop.Advice; | ||
|
||
/** | ||
* @author derekyi | ||
* @date 2020/12/6 | ||
*/ | ||
public interface BeforeAdvice extends Advice { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/springframework/aop/MethodBeforeAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.springframework.aop; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* @author derekyi | ||
* @date 2020/12/6 | ||
*/ | ||
public interface MethodBeforeAdvice extends BeforeAdvice { | ||
|
||
void before(Method method, Object[] args, Object target) throws Throwable; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/springframework/aop/framework/adapter/MethodBeforeAdviceInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.springframework.aop.framework.adapter; | ||
|
||
import org.aopalliance.intercept.MethodInterceptor; | ||
import org.aopalliance.intercept.MethodInvocation; | ||
import org.springframework.aop.MethodBeforeAdvice; | ||
|
||
/** | ||
* @author derekyi | ||
* @date 2020/12/6 | ||
*/ | ||
public class MethodBeforeAdviceInterceptor implements MethodInterceptor { | ||
|
||
private MethodBeforeAdvice advice; | ||
|
||
public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) { | ||
this.advice = advice; | ||
} | ||
|
||
@Override | ||
public Object invoke(MethodInvocation invocation) throws Throwable { | ||
//在执行被代理方法之前,先执行before advice操作 | ||
this.advice.before(invocation.getMethod(), invocation.getArguments(), invocation.getThis()); | ||
return invocation.proceed(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/java/org/springframework/test/common/WorldServiceBeforeAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.springframework.test.common; | ||
|
||
import org.springframework.aop.MethodBeforeAdvice; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* @author derekyi | ||
* @date 2020/12/6 | ||
*/ | ||
public class WorldServiceBeforeAdvice implements MethodBeforeAdvice { | ||
|
||
@Override | ||
public void before(Method method, Object[] args, Object target) throws Throwable { | ||
System.out.println("BeforeAdvice: do something before the earth explodes"); | ||
} | ||
} |