首页 > 代码库 > applicationContext.xml(Spring)

applicationContext.xml(Spring)

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)