如下配置方式spring2.5和spring3.0同樣,新的版本中並無改變對於切面的調整:java
- package com.utils.spring.businessafter;
- import java.lang.reflect.Method;
- import org.apache.log4j.Logger;
- import org.springframework.aop.AfterReturningAdvice;
- import org.springframework.context.ApplicationContext;
- import com.winning.bi.domain.MRuleExe;
- import com.winning.utils.Constant;
- public class BusinessAfter implements AfterReturningAdvice{
- private final Logger logger = Logger.getLogger(BusinessAfter.class);
- private ApplicationContext applicationContext;
- public void afterReturning(Object returnValue, Method method,Object[] args, Object target) throws Throwable {
- applicationContext=Constant.SPRING_CONTAINER;
- //添加任務方法
- if ("exeMTRuleJob".equals(method.getName())) {
- MRuleExe mRuleExe=(MRuleExe)args[0]; //得到參數
- if(mRuleExe.getAutoExe()==Constant.TRUE){ //自定執行的任務
- new AutoTaskExecuteUtil().addMRuleExe(mRuleExe);
- }
- }
- //刪除任務方法
- else if("deleteExe".equals(method.getName())){
- MRuleExe mRuleExe=(MRuleExe)args[0]; //得到參數
- if(mRuleExe.getAutoExe()==Constant.TRUE){ //自定執行的任務
- new AutoTaskExecuteUtil().delMRuleExe(mRuleExe);
- }
- }
- }
- }
- <!-- spring後置通知 配置 -->
- <bean id="after" class="com.utils.spring.businessafter.BusinessAfter"/>
- <bean id="bussinessafter" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
- <property name="patterns">
- <list>
- <value>com.bi.service.impl.KettleServiceImpl\.exeMTRuleJob</value><!-- 添加任務方法 -->
- <value>com.bi.service.impl.MRuleExeServiceImpl\.deleteExe</value><!-- 刪除任務方法 -->
- </list>
- </property>
- <!-- 指定Advice -->
- <property name="advice">
- <ref bean="after" />
- </property>
- </bean>
- <bean id="businessaop" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
- <property name="interceptorNames">
- <list>
- <value>bussinessafter</value>
- </list>
- </property>
- <property name="beanNames">
- <list>
- <value>kettleService</value>
- <value>mruleExeService</value>
- </list>
- </property>
- </bean>