1.前置增强
引入一个节点
aspectjweaver
<!--
https://mvnrepository.com/artifact/aspectj/aspectjweaver
-->
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
aspectjweaver
<!--
-->
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.3<
ersion>
</dependency>
</dependency>
添加完节点后,加入xsd约束

public interface ISomeDAO { public void doSome(); } public class ISomeDAOImpl implements ISomeDAO { public void doSome() { System.out.println("国庆节"); } }

public interface ISomeService { public void doSome(); } public class ISomeServiceImpl implements ISomeService{ public ISomeDAO getDao() { return dao; } public void setDao(ISomeDAO dao) { this.dao = dao; } private ISomeDAO dao; public void doSome() { dao.doSome(); } }

public class MyBoforeAdvice implements MethodBeforeAdvice { public void before(Method method, Object[] objects, Object o) throws Throwable { System.out.println("日志记录"); } }

@Test public void test01(){ ApplicationContext context=new ClassPathXmlApplicationContext("applicationContextaop.xml"); ISomeService service = (ISomeService) context.getBean("someService"); service.doSome(); }