码迷,mamicode.com
首页 > 移动开发 > 详细

applicationContext.xml(Spring)

时间:2017-07-23 18:09:36      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:ann   strong   expr   org   app   方式   sch   proxy   支持   

bean和aspect都通过注释的方式

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
xmlns:context="http://www.springframework.org/schema/context"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
         xmlns:aop="http://www.springframework.org/schema/aop"  
         xmlns:tx="http://www.springframework.org/schema/tx"  
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd  
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd  
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  
         <!--注释方式扫描bean-->
         <context:annotation-config/>
        <!-- 对以manager开头的包进行扫描 -->
        <context:component-scan base-package="manager"/>
    <!-- 启用Spring对基于@AspectJ aspects的注释支持 -->  
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>  
</beans> 

 

bean通过xml配置,aspect通过注释

<?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"  
         xmlns:tx="http://www.springframework.org/schema/tx"  
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd  
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd  
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
           http://www.springframework.org/schema/context">  
  
    <!-- 启用Spring对基于@AspectJ aspects的注释支持 -->  
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>  
   <bean id="xxx"  class="xxx"></bean>  
</beans>  

bean通过注释,aspect通过xml配置

<?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:context="http://www.springframework.org/schema/context"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-4.1.xsd
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">    
     
     
        <!-- 通过annotation来进行bean的创建 -->
        <context:annotation-config/>
        <!-- 对以manager开头的包进行扫描 -->
        <context:component-scan base-package="manager"/>
        <!-- 通过xml方式来配置AOP -->
        <aop:config>       
            <!-- 声明在哪些位置我要加入这个切面 -->
             <aop:pointcut expression="execution(* find*(..))" id="testpointcut"/>
              <!-- 声明一个切面 -->                      
            <aop:aspect id="AspectJAdvice" ref="aspectJAdvice">
                <aop:before method="doBefore" pointcut-ref="testpointcut"/>
                 <aop:after method="doAfter" pointcut-ref="testpointcut"/>
                  <aop:around method="doAround" pointcut-ref="testpointcut"/>
                  <!--一定要有return属性-->
                 <aop:after-returning method="doReturn" returning="retVal" pointcut-ref="testpointcut"/>
                  <!--一定要有throwing属性-->   
              <aop:after-throwing throwing="ex" method="doThrowing" pointcut-ref="testpointcut"/>
                 
            </aop:aspect>
        </aop:config>        
</beans>

 

applicationContext.xml(Spring)

标签:ann   strong   expr   org   app   方式   sch   proxy   支持   

原文地址:http://www.cnblogs.com/kundeg/p/7225280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!