Preface
In order to achieve performance tuning, you need to first count the execution time of each method, directly before and after the log output is too cumbersome, you can use AOP to add time statistics added dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> Spring-boot-starter-aop</artifactid>
</dependency>
add configuration to Application.properties
Spring.aop.auto=true
The Spring.aop.auto property is turned on by default, which means that as long as the AOP dependency is introduced, the default has been increased by @enableaspectjautoproxy. Remember to never add extra information, such as @enableaspectjautoproxy. Implementing specific Code
@Component @Aspect public class Logaspect {private static final log = Logfactory.getlog (Logaspect.class);
/** * defines a pointcut.
* Explanation: * * ~ the first * represents any modifier and any return value. * ~ the second * is defined in the Web package or the sub package * ~ Third * Any method * ~ ...
Matches any number of parameters. * * @Pointcut (* Execution (* com.wedo.stream.service).
*.*(..))") public void Logpointcut () {} @org. Aspectj.lang.annotation.Around ("Logpointcut ()") Public Object Doaround (Proceed
Ingjoinpoint joinpoint) throws throwable{//Log.debug ("logpointcut" + joinpoint + "T");
Long start = System.currenttimemillis ();
try {Object result = Joinpoint.proceed ();
Long end = System.currenttimemillis ();
Log.error ("+++++around" + joinpoint + "\tuse Time:" + (End-start) + "ms!");
return result;
catch (Throwable e) {Long end = System.currenttimemillis ();
Log.error ("+++++around" + joinpoint + "\tuse Time:" + (End-start) + "Ms with exception:" + E.getmessage ());
Throw e; }
}
}
pay attention to the problem
Post-AOP methods do not return values correctly
This proxy method must return a value, otherwise there will be no return value in the code.
This is wrong. Public
void Doaround (Proceedingjoinpoint joinpoint) {}
This is written in spring's documentation: the Spring AOP section uses JDK dynamic proxies or cglib to create proxies for target objects. If the target of the proxy implements at least one interface, the JDK dynamic proxy is used. All interfaces implemented by the target type will be represented. If the target object does not implement any interfaces, a CGLIB proxy is created.
The default is JDK dynamic proxy, changed to Cglib