Spring + AOP

AOP:

Oriented Programming with respect to OOP programming section

In order to decouple the Spring AOP, AOP allows the behavior of the same shared a set of classes

Spring supports Aspect annotation type declaration section Programming

 

The following sample code:

In order to address the implementation of a method, you need to switch databases

@Aspect
@Component
public class DataSourceAspect {
    @Before("execution(* cn.com.citydo.web.mapper.oracle.ExecuteSqlFromOracleMapper.execute(..))")
    public void setSecondaryDataSource(JoinPoint point) {
        DatabaseContextHolder.setDatabaseType(DatabaseType.secondaryDb);
    }

    @After("execution(* cn.com.citydo.web.mapper.oracle.ExecuteSqlFromOracleMapper.execute(..))")
    public void setPrimaryDataSource(JoinPoint point) {
        DatabaseContextHolder.setDatabaseType(DatabaseType.primaryDb);
    }
}

1) @Aspect Declaring an aspect

2) @Component let this become a spring section container-managed bean

3) @PointCut notes sound Mingqie point

 

 

 

Guess you like

Origin blog.csdn.net/yss1019/article/details/81982774