AOP SIMPLE EXAMPLE

zhaozj2021-02-12  157

THERE IS A Simple Spring Aop Style Example Took Me Some Time To Finish It. It's so easy and enjoyable. Hope it would do some help to you.

Code:

import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; / ** * User: xxxxxxx * Date: Dec 17, 2003 * Time: 7:54:56 PM * all rights reserved by utstarcom * / public class myInterceptor implements MethodInterceptor {private final Log logger = LogFactory.getLog (MyInterceptor.class); public Object invoke (MethodInvocation methodInvocation) throws Throwable {logger.info ( "Beginning method:" methodInvocation.getMethod () getDeclaringClass () "::" methodInvocation.getMethod ().. GetName ()); for (int i = 0; i

Code:

Import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory; / ** * user: xxxxxxxx * Date: Dec 17, 2003 * Time: 8:07:41 PM * all rights reserved by utstarcom * / public class HelloWorldImpl implements HelloWorld {private final static Log logger = LogFactory.getLog (HelloWorldImpl.class); public void sayHello (int age, String Name) {Logger.info ("Age:" Age "Name:" Name);}} code:

import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import java.io.InputStream; import java.io.FileInputStream; / ** * User:

Code:

HelloWorld myInterceptor helloworld code:

/ ** * user: xxxxx * Date: DEC 17, 2003 * Time: 8:17:19 Pm * all rights reserved by utstarcom * / public Interface HelloWorld {Void Sayhello (Int Age, String Name);

Come from

http://spring.jactiongroup.net/viewtopic.php?t=144

转载请注明原文地址:https://www.9cbs.com/read-6533.html

New Post(0)