Those years caught up with Spring[3]-AOP

Core concepts:

Cut face, Aspect: actually, we need to define the AOP class, which encapsulates the functionality of the code.

Guide bag:

Those years caught up with Spring[3]-AOP
Guide Package


Implementation code:

Package com.spring.aop; import java.util.Date; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect public class LogAop {@Before ("execution (public void com.spring.dao.impl.StudentDaoImpl.* (..))" public void (logBefore) date=new (Date) {Date (System.out.println); "before the execution of the method execution log");}}
Package com.spring.dao; public, interface, StudentDao, {public, void, insert (); public, void, update ();}
Package com.spring.aop; import java.util.Date; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect public class LogAop {@Before ("execution (public void com.spring.dao.impl.StudentDaoImpl.* (..))" public void (logBefore) date=new (Date) {Date (System.out.println); "before the execution of the method execution log");}}
Package com.spring.dao; public, interface, StudentDao, {public, void, insert (); public, void, update ();}
Package com.spring.dao.impl; import com.spring.dao.StudentDao; public class StudentDaoImpl implements StudentDao public void (insert) {@Override {System.out.println ("method insert");} @Override public void (update) {System.out.println ("update method!");}}
Package com.spring.services; import com.spring.dao.StudentDao; public class StudentServices StudentDao public void {private Dao; setDao (StudentDao Dao) {this.dao = Dao;} public void insert (dao.insert) {public}); (void) update (dao.update () {}};
Package com.spring.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.spring.services.StudentServices; public class test01 static void main {public (String[] args) {ApplicationContext context=new ClassPathXmlApplicationContext ("bean-aop-annotation.xml"); StudentServices ss= (StudentServices) context.getBean ("studentServices"); (ss.insert) (ss.update);}};

XML configuration:

< XML? Version= "1" encoding= "UTF-8" > < beans? Xmlns= "http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:aop= "http://www.springframework.org/schema/aop" xsi:schemaLocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema /aop/spring-aop-3.0.xsd > < aop:aspectj-autoproxy> < /aop:aspectj-autoproxy> < bean id=" studentServices "class=" com.spring.services.StudentServices "> < property; name=" Dao "ref=" studentDao "> < / property> < /bean> bean; < ID = studentDao, class=, com.spring.dao.impl.StudentDaoImpl, > /bean> < bean; id=; logAop; class=; com.spring.aop.LogAop; > < < /bean> < /beans>

Run results:
executes the log before the method execution —
method insert
executes the log before the method execution —
, update, method!

Pay attention to study together!

Those years caught up with Spring[3]-AOP
cicadas Hall