AOP usage -- BeanNameAutoProxyCreator usage

本文详细介绍了在Spring框架中使用Aspect Oriented Programming (AOP)和Inversion of Control (IOC)的基本配置方法。包括如何正确配置ApplicationContext而非BeanFactory,如何设置BeanNameAutoProxyCreator以实现AOP代理,以及所需的jar文件列表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1) Must use ApplicationContext, can't use BeanFactory.

Example:

ApplicationContext factory = new ClassPathXmlApplicationContext(new String[]{"spring.xml"});

 

2) BeanNameAutoProxyCreator bean must include property as below.

<property name="proxyTargetClass" value="true"/>

Example:

<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">

     <property name="proxyTargetClass" value="true"/>

     <property name="interceptorNames">

        <list><value>loggingAroundAdvisor</value></list>

    </property>

    <property name="beanNames">

        <list><value>*world</value></list>

    </property>

 </bean>

<bean id="helloworld" class="com.xqstation.test.spring.HelloWorld"/>

   

3) jar files must have (Spring 1.2.8)

lib\aopalliance\aopalliance.jar,

lib\cglib\cglib-nodep-2.1_3.jar,

 

 

 A very simple Spring AOP example is attached.

 

 BeanFactory or ApplicationContext?

Users are sometimes unsure whether a BeanFactory or an ApplicationContext is best suited for use in a particular situation. A BeanFactory pretty much just instantiates and configures beans. An ApplicationContext also does that, and it provides the supporting infrastructure to enable lots of enterprise-specific features such as transactions and AOP.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值