Using schema
1.AroundLogger class
1 //define a JavaBean that contains an enhancement method2 Public classaroundlogger{3 //wrapping Enhancement processing for annotation mode4 Private Static FinalLogger log = Logger.getlogger (Aroundlogger.class);5 PublicObject Aroundlogger (proceedingjoinpoint JP) {6Log.info ("A Calls" +jp.gettarget () + "+jp.getsignature (). GetName () +" method, the method parameter is: "7+arrays.tostring (Jp.getargs ()));8 Try {9Object result = Jp.proceed ();//call the target method to get the return value of the target methodTenLog.info ("A Calls" +jp.gettarget () + "+jp.getsignature (). GetName () +" method, the method return value is: " One+result); A returnresult; -}Catch(Exception e) { -Log.error (Jp.getsignature (). GetName () + "method throws Exception" +e); the e.printstacktrace (); -}Catch(Throwable e) { - //TODO auto-generated Catch block - e.printstacktrace (); + } - return NULL; + } A}
2.spring configuration file
1<bean id= "DAO"class= "Com.dao.impl.IUserDaoImpl" ></bean>2<bean id= "Biz"class= "Com.biz.impl.IUserBizImpl" >3<property name= "DAO" ref= "DAO" ></property>4</bean>5<!--declaring an enhancement method in the same class-6<bean id= "Thelogger"class= "Com.aop.AroundLogger" ></bean>7<!--configuring Facets--8<aop:config>9<!--defining Pointcuts--Ten<aop:pointcut expression= "Execution (* com.biz.iuserbiz.* (..))" id= "Pointcut"/> One<!--introduced with enhanced beans-- A<aop:aspect ref= "Thelogger" > -<!--define the Aroundlogger method as a final enhancement and introduce a pointcut-- -<aop:around method= "Aroundlogger" pointcut-ref= "Pointcut"/> the</aop:aspect> -</aop:config>
3. Test similar using schema to configure facets
4. Test results
Defines a JavaBean (final enhancement) that contains an enhanced method