parent
febdcd66fe
commit
8458a90031
@ -0,0 +1,12 @@
|
||||
package proxy.spring;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("app_auto.xml");
|
||||
Tank tank = (Tank)context.getBean("tank");
|
||||
tank.move();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package proxy.spring;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Tank {
|
||||
public void move(){
|
||||
System.out.println("tank is moving...");
|
||||
try {
|
||||
Thread.sleep(new Random().nextInt(10000));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package proxy.spring;
|
||||
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
|
||||
@Aspect
|
||||
public class TimeProxy {
|
||||
|
||||
@Before("execution(void proxy.spring.Tank.move())")
|
||||
public void before(){
|
||||
System.out.println("start time: " + System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@After("execution(void proxy.spring.Tank.move())")
|
||||
public void end(){
|
||||
System.out.println("end time: " + System.currentTimeMillis());
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop.xsd">
|
||||
<aop:aspectj-autoproxy/>
|
||||
<bean id="tank" class="proxy.spring.Tank"/>
|
||||
<bean id="timeProxy" class="proxy.spring.TimeProxy"/>
|
||||
</beans>
|
Loading…
Reference in new issue