spring中aop编程

xml方式实现AOP编程,注解方式略

<?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:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">
        
 
     <!-- IOC容器的配置,要创建的所有的对象都配置在这里 -->
     <!-- 普通方法 -->
     <!-- <bean id = "adminDao" class="DI.AdminDao" scope="singleton"></bean>
     
     <bean id = "adminService" class="DI.AdminService" scope="singleton">
        <property name="adminDao" ref="adminDao"></property>
     </bean>
     
     <bean id = "adminAction" class="DI.AdminAction" scope="prototype">
        <property name="service" ref="adminService"></property>
     </bean> -->
     <!-- 内部bean 只能自己使用-->
     <!-- <bean id = "adminAction" class="DI.AdminAction" scope="prototype">
         <property name="service">
             <bean id="adminService" class="DI.AdminService" scope="singleton">
                <property name="adminDao">
                   <bean id = "adminDao" class="DI.AdminDao" scope="singleton"></bean>
                </property>
             </bean>
         </property>
     </bean> -->
     <bean name = "userDao" class="spring02.UserDao"></bean>
     <bean name = "aop" class="spring02.Aop"></bean>
   <aop:config>
       <aop:pointcut expression="execution(* spring02.UserDao.*(..))" id="pt"/>
       <aop:aspect ref="aop">
         <aop:after method="over" pointcut-ref="pt"/>
         <aop:before method="begin" pointcut-ref="pt"/>
       </aop:aspect>
     </aop:config>
</beans>

猜你喜欢

转载自blog.csdn.net/erchouchou/article/details/81367172