aspectj xml
生活随笔
收集整理的這篇文章主要介紹了
aspectj xml
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.接口和類
1.1?ISomeService 接口
public interface ISomeService {public void doSome();public void dade(); }1.2 ?SomeService類
public class SomeService implements ISomeService {//核心業務public void doSome(){System.out.println("我們都要找到Java開發工作,薪資6,7,8,9,10K");}public void dade() {//異常//int sun=5/0;System.out.println("++++++++++++++de+++++++++++++");}}1.3 ?MyAspect 類
public class MyAspect {//前置增強public void before(){System.out.println("=====before========");}//后置增強public void afterReturing(){System.out.println("=====after========");}//后置增強 目標方法的返回值public void afterReturing(String result){System.out.println("=====后置通知方法 result========"+result);}//環繞通知public Object around(ProceedingJoinPoint pjp) throws Throwable {System.out.println("目標方法執行前執行");Object result = pjp.proceed();System.out.println("目標方法執行后執行");String temp=null;if (result!=null) {temp = (String) result;temp=temp.toUpperCase();}return temp;}//異常通知public void afterThrowing(){System.out.println("異常通知");}//異常通知public void afterThrowing(Exception ex){System.out.println("異常通知 ex="+ex.getMessage());}//最終通知public void after(){System.out.println("最終通知");}}2.xml文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd "><!--01.目標對象--><bean id="someService" class="cn.bdqn.spring18.SomeService"></bean><!--02.增強類--><bean id="aspect" class="cn.bdqn.spring18.MyAspect"></bean><!--aop--><aop:config><!--設置一個切點--><aop:pointcut id="mycut" expression="execution(* *..spring18.*.*(..))"></aop:pointcut><aop:aspect ref="aspect"><aop:before method="before" pointcut-ref="mycut"></aop:before><aop:after-returning method="afterReturing" pointcut-ref="mycut"></aop:after-returning><aop:after-returning method="afterReturing(java.lang.String)" returning="result" pointcut-ref="mycut"></aop:after-returning><aop:around method="around" pointcut-ref="mycut"></aop:around><aop:after-throwing method="afterThrowing" pointcut-ref="mycut"></aop:after-throwing><aop:after-throwing method="afterThrowing(java.lang.Exception)" throwing="ex" pointcut-ref="mycut"></aop:after-throwing><aop:after method="after" pointcut-ref="mycut"></aop:after></aop:aspect></aop:config> </beans>3.測試類
//aspectj xml @Testpublic void test20(){ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContextspring16.xml");ISomeService service = (ISomeService) ctx.getBean("someService");service.doSome();service.dade();}?
轉載于:https://www.cnblogs.com/qjt970518--/p/7293925.html
總結
以上是生活随笔為你收集整理的aspectj xml的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unrecognised tag: 'b
- 下一篇: ctf变量覆盖漏洞