用代码学习Spring:IoC、AOP(下)
2007-02-14 08:59
543 查看
用代码学习Spring:IoC、AOP(上)
7 建立配置文件组织上面的类之间的关系,AOP有切入点和增强这两个重要的概念,把两个概念结合到一起,就是一个在某个方法执行的时候附加执行,切入点表示 在哪里附加,增强表示附加什么,配置文件中的myPointcut表示切入点,myInterceptor表示增强的内容,myAdvisor表示增强 器,
即两者的结合,在bo这个bean中,我们把这个增强器附加到了bo这个bean上。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="businessObjectImpl" class="BusinessObjectImpl">
<property name="words">
<value>正在执行业务方法</value>
</property>
</bean>
<bean id="myInterceptor" class="MyInterceptor">
<property name="before">
<value>执行业务方法前</value>
</property>
<property name="after">
<value>执行业务方法后</value>
</property>
</bean>
<bean id="myPointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut">
<property name="patterns">
<list>
<value>BusinessObject.doSomething</value>
</list>
</property>
</bean>
<bean id="myAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="pointcut" ref="myPointcut"/>
<property name="advice" ref="myInterceptor"/>
</bean>
<bean id="bo" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref local="businessObjectImpl"/>
</property>
<property name="proxyInterfaces">
<value>BusinessObject</value>
</property>
<property name="interceptorNames">
<list>
<value>myInterceptor</value>
<value>myAdvisor</value>
</list>
</property>
</bean>
</beans><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="businessObjectImpl" class="BusinessObjectImpl">
<property name="words">
<value>正在执行业务方法</value>
</property>
</bean>
<bean id="myInterceptor" class="MyInterceptor">
<property name="before">
<value>执行业务方法前</value>
</property>
<property name="after">
<value>执行业务方法后</value>
</property>
</bean>
<bean id="myPointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut">
<property name="patterns">
<list>
<value>BusinessObject.doSomething</value>
</list>
</property>
</bean>
<bean id="myAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="pointcut" ref="myPointcut"/>
<property name="advice" ref="myInterceptor"/>
</bean>
<bean id="bo" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref local="businessObjectImpl"/>
</property>
<property name="proxyInterfaces">
<value>BusinessObject</value>
</property>
<property name="interceptorNames">
<list>
<value>myInterceptor</value>
<value>myAdvisor</value>
</list>
</property>
</bean>
</beans>
8 运行Main类,观察控制台输出结果,重新审查代码,反思为什么会出现这种结果。
用代码学习Spring:IoC、AOP(上)
7 建立配置文件组织上面的类之间的关系,AOP有切入点和增强这两个重要的概念,把两个概念结合到一起,就是一个在某个方法执行的时候附加执行,切入点表示 在哪里附加,增强表示附加什么,配置文件中的myPointcut表示切入点,myInterceptor表示增强的内容,myAdvisor表示增强 器,
即两者的结合,在bo这个bean中,我们把这个增强器附加到了bo这个bean上。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="businessObjectImpl" class="BusinessObjectImpl">
<property name="words">
<value>正在执行业务方法</value>
</property>
</bean>
<bean id="myInterceptor" class="MyInterceptor">
<property name="before">
<value>执行业务方法前</value>
</property>
<property name="after">
<value>执行业务方法后</value>
</property>
</bean>
<bean id="myPointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut">
<property name="patterns">
<list>
<value>BusinessObject.doSomething</value>
</list>
</property>
</bean>
<bean id="myAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="pointcut" ref="myPointcut"/>
<property name="advice" ref="myInterceptor"/>
</bean>
<bean id="bo" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref local="businessObjectImpl"/>
</property>
<property name="proxyInterfaces">
<value>BusinessObject</value>
</property>
<property name="interceptorNames">
<list>
<value>myInterceptor</value>
<value>myAdvisor</value>
</list>
</property>
</bean>
</beans><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="businessObjectImpl" class="BusinessObjectImpl">
<property name="words">
<value>正在执行业务方法</value>
</property>
</bean>
<bean id="myInterceptor" class="MyInterceptor">
<property name="before">
<value>执行业务方法前</value>
</property>
<property name="after">
<value>执行业务方法后</value>
</property>
</bean>
<bean id="myPointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut">
<property name="patterns">
<list>
<value>BusinessObject.doSomething</value>
</list>
</property>
</bean>
<bean id="myAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="pointcut" ref="myPointcut"/>
<property name="advice" ref="myInterceptor"/>
</bean>
<bean id="bo" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref local="businessObjectImpl"/>
</property>
<property name="proxyInterfaces">
<value>BusinessObject</value>
</property>
<property name="interceptorNames">
<list>
<value>myInterceptor</value>
<value>myAdvisor</value>
</list>
</property>
</bean>
</beans>
8 运行Main类,观察控制台输出结果,重新审查代码,反思为什么会出现这种结果。
用代码学习Spring:IoC、AOP(上)
相关文章推荐
- 用代码学习Spring:IoC、AOP(上)
- 用代码学习Spring:IoC、AOP(上)
- 用代码学习Spring:IoC、AOP
- 用代码学习Spring:IoC、AOP
- 用代码学习Spring:IoC、AOP(下)
- 用代码学习Spring:IoC、AOP
- 用代码学习Spring:IoC、AOP
- 用代码学习Spring:IoC、AOP
- 用代码学习Spring:IoC、AOP
- 用代码一步步学习Spring:IoC,AOP
- Spring学习总结——静态代理、JDK与CGLIB动态代理、AOP+IoC
- Spring IOC及AOP学习总结
- Spring IOC及AOP学习总结
- Spring学习——IOC和AOP的理解
- Spring学习笔记1——IOC: 尽量使用注解以及java代码
- Spring(IOC/AOP)注解学习
- Spring学习笔记--AOP和IOC、SSH整合
- Spring源码学习 ------ IoC——AOP
- 学习AOP之透过Spring的Ioc理解Advisor
- Spring学习总结(二)——静态代理、JDK与CGLIB动态代理、AOP+IoC