Aop小列子

//引入节点
<!-- https://mvnrepository.com/artifact/aspectj/aspectjweaver-->
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.3</version>
</dependency>
//接口dao
public interface ISomeDAO {
public void doSome();
}

//实现接口Dao
public class SomeDaoImpl implements ISomeDAO {
public void doSome() {
System.out.println("国庆节快乐");
}
}
Service接口
public interface ISomeService {
public void doSome();
}

//service接口实现
public class SomeServiceImpl implements  ISomeService {
private ISomeDAO dao;

public ISomeDAO getDao() {
return dao;
}

public void setDao(ISomeDAO dao) {
this.dao = dao;
}

public void doSome() {

dao.doSome();
}
}
xml配置


  //前置增强<bean id="beforeAdvice" class="cn.happy.day03.aop.MyBeforeAdvice">
//后置增强<bean id="afterAvice" class="cn.happy.day03.aop.MyafterAdvice">

</bean>
<aop:config>
<aop:pointcut id="mypointcut" expression="execution(* *..dao.*.*(..))"></aop:pointcut>
<aop:advisor advice-ref="afterAvice" pointcut-ref="mypointcut"></aop:advisor>
</aop:config>

//单测
    public void test01(){
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContextday03.xml");
/*HappyServices service=(HappyServices)context.getBean("service");
service.work();
System.out.println(service);*/
ISomeService service=(ISomeService)context.getBean("someService");
service.doSome();
}
原文地址:https://www.cnblogs.com/spghs/p/7637833.html