Springboot Integrated AOP As the example would have been simple, but there could be a hole in the middle of the process.
Come first official standard practice:
The version of my springboot is 1.5.6.RELEASE.
It's OK to add AOP dependencies to Pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> spring-boot-starter-aop</artifactid>
<scope>compile</scope>
</dependency>
Then you can use it like standard AOP, and here's an example:
@Aspect
@Component Public
class Commonlog {
private static final Logger Syslogger = Logger.getlogger ( Statedefine.sys_log);
@Pointcut ("Execution" (* org.redstarofsleep.aopsample. *service.* (..)) ")
public void Service () {};
/**
* Description:service method automatically logs when throwing exceptions
* @param ex
/@AfterThrowing (pointcut= "service ()", throwing= ' ex ') public
void Exceptionofmethod (Joinpoint joinpoint, Exception ex) {
// Syslogger.error ( Logutil.getexceptions (ex)); Syslogger.error ("* * * ERROR service occurred:", ex);
Log the exception trace
syslogger.error ("### error service==========>>" + logutil.getinformation (joinpoint));
Logutil.logexceptiontrace (ex);
}
Ben came here to finish it. But this code compiles does not have the error, a start to report jointpoint this class cannot find. Rarely strange.
There may be a problem with this version of the consolidated package, this version of the SPRING-BOOT-STARTER-AOP Consolidated Aspectjweaver version is 1.8.10, replaced by the 1.8 7 problem, so the pom modification is as follows:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> spring-boot-starter-aop</artifactid>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.aspectj</groupId>
<artifactid>aspectjweaver</ artifactid>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>