New AOP facets, time-consuming statistical system methods.
Package COM.XYZQ.AFA.PBANK.CONSOLE.AOP;
/** * Created by YANG on 2017-7-6.
*/import Com.xyzq.afa.util.PBankUtil;
Import Org.aspectj.lang.JoinPoint;
Import Org.aspectj.lang.ProceedingJoinPoint;
Import Org.aspectj.lang.Signature;
Import Org.aspectj.lang.annotation.After;
Import Org.aspectj.lang.annotation.Around;
Import Org.aspectj.lang.annotation.Aspect;
Import Org.aspectj.lang.annotation.Before;
Import Org.aspectj.lang.reflect.MethodSignature;
Import Org.slf4j.Logger;
Import Org.slf4j.LoggerFactory;
Import org.springframework.stereotype.Component;
Import Java.util.Calendar;
Import java.util.Collection;
Import Java.util.Map;
Import Java.util.UUID; @Component @Aspect public class Timeconsumelogaspect {private threadlocal<long> time = new threadlocal<long&
gt; ();
Private threadlocal<string> tag = new threadlocal<string> ();
@Autowired//Private Permissionservice permissionservice; @Around ("Execution (* com.xyzq.afa.pbank.console.*.service*).*.*impl.* (..)) ") Public Object Aroundservice (Proceedingjoinpoint joinpoint) throws Throwable {Logger Logger = Loggerfactory.getlog
GER (Joinpoint.gettarget (). GetClass (). GetName ());
Time.set (System.currenttimemillis ());
Tag.set (Uuid.randomuuid (). toString ());
String username = (string) securityutils.getsubject (). Getprincipal ();
StringBuffer msg = new StringBuffer () by spelling the parameter into a string; Retrieve the methods parameter types (static): final Signature Signature = Joinpoint.getstaticpart (). Getsignatu
Re ();
if (signature instanceof methodsignature) {final Methodsignature ms = (methodsignature) signature;
Final class<?>[] parametertypes = Ms.getparametertypes ();
For (final class<?> pt:parametertypes) {msg.append ("Parameter type:"). Append (PT); }}//Retrieve the Runtime method arguments (dynamic) if (Logger.isdebugenAbled ()) {for (Final Object Argument:joinPoint.getArgs ()) {msg.append ("Parameter Value:")
;
Msg.append (pbankutil.getobjectallattributes (argument)); }} else {for (final Object Argument:joinPoint.getArgs ()) {Msg.append ("Parameter
Value: ");
Msg.append (argument);
}} methodsignature ms = (methodsignature) joinpoint.getsignature (); Before Service execution, log logger.info ("[TagId: {}]service starting") is logged.
Method: {} ({}) ", Tag.get (), Ms.getmethod (). GetName (), msg.tostring ());
Executes the target method and obtains its return value Object RTN = Joinpoint.proceed (Joinpoint.getargs ());
int size =-1;
if (RTN instanceof Collection) {size = ((Collection) RTN). Size ();
} else if (Rtn instanceof Map) {size = (map) RTN). Size ();
//service log if after execution (logger.isdebugenabled ()) { Logger.info ("[TagId: {}]service finished.
Used time {}ms. Return: {} ", Tag.get (), System.currenttimemillis ()-Time.get (), RTN); } else {if (Size >-1) {//Collection-type return value, in non-debug mode only prints the collection's size Logger.info ("[Tagi D: {}]service finished.
Used time {}ms. Return: {} ", Tag.get (), System.currenttimemillis ()-Time.get (), size); } else {//non-collection type return value, print logger.info directly ("[TagId: {}]service finished.
Used time {}ms. Return: {} ", Tag.get (), System.currenttimemillis ()-Time.get (), RTN);
}} return RTN;
} @Before ("Execution (* com.xyzq.afa.pbank.console.web.controllers.*.*controller.* (..))") public void Beforecontroller (Joinpoint joinpoint) {Logger Logger = Loggerfactory.getlogger (Joinpoint.gettarget ().
GetClass (). GetName ());
Time.set (System.currenttimemillis ()); Tag.sET (Uuid.randomuuid (). toString ());
StringBuffer msg = new StringBuffer () by spelling the parameter into a string; Retrieve the methods parameter types (static): final Signature Signature = Joinpoint.getstaticpart (). Getsignatu
Re ();
if (signature instanceof methodsignature) {final Methodsignature ms = (methodsignature) signature;
Final class<?>[] parametertypes = Ms.getparametertypes ();
For (final class<?> pt:parametertypes) {msg.append ("Parameter type:"). Append (PT);
}}//Retrieve the Runtime method arguments (dynamic) if (logger.isdebugenabled ()) {
For (final Object Argument:joinPoint.getArgs ()) {msg.append ("Parameter value:");
Msg.append (pbankutil.getobjectallattributes (argument)); }} else {for (final Object Argument:joinPoint.getArgs ()) {Msg.append ("Parameter Value:");
Msg.append (argument);
}} methodsignature ms = (methodsignature) joinpoint.getsignature ();
Confirm User Login information//Users loginuser = Permissionservice.getloginuser (); Logger.debug ("[TagId: {} UserName {}]controller starting. Method: {} ({}) ", Tag.get (), (String) Securityutils.getsubject (). Getprincipal (),//Ms.getmethod (). GetName
(), msg.tostring ()); Logger.info ("[TagId: {}]controller starting.
Method: {} ({}) ", Tag.get (), Ms.getmethod (). GetName (), msg.tostring ());
} @After ("Execution (* com.xyzq.afa.pbank.console.web.controllers.*.*controller.* (..))") public void Aftercontroller (Joinpoint joinpoint) {Logger Logger = Loggerfactory.getlogger (Joinpoint.gettarget (). g
Etclass (). GetName ());
Calendar calendar = Calendar.getinstance ();
Calendar.settimeinmillis (System.currenttimemillis ()); Methodsignature ms = (methodsignature) Joinpoint.getsiGnature (); Logger.info ("[TagId: {} UserName {}]controller succeeded. Used time {}ms. Method: {} {} ", Tag.get (), (String) Securityutils.getsubject (). Getprincipal (),//calendar.
Gettimeinmillis ()-Time.get (), Ms.getmethod (). GetName (), Ms.getparameternames ()); Logger.info ("[TagId: {}]controller succeeded. Used time {}ms. Method: {} {} ", Tag.get (), Calendar.gettimeinmillis ()-Time.get (), Ms.getmethod (). GetName
(), Ms.getparameternames ()); }
}
Configuration XML File Applicationcontext.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xs
I= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xsi:schemalocation= "Http://www.springframework.org/schema /beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/
Context http://www.springframework.org/schema/context/spring-context-2.5.xsd "default-lazy-init=" true "> <context:annotation-config/> <context:component-scan base-package= "Com.xyzq"/> <aop:aspectj-auto Proxy proxy-target-class= "false"/> <bean name= "Bartplaceholderconfigurer" class= " Com.xyzq.simpson.bart.client.spring.BartPlaceholderConfigurer "> <property name=" Location "value=" Classpath: Config/app.properties "/> </bean> </beans>
Throwing exceptions after starting the project is as follows:
: Line the XML document from file [D:\IdeaWorks\PrivateBank_test\pbank-console\pbank-console-web\target\ Pbank-console-web-1.0.0\web-inf\classes\config\spring\applicationcontext.xml] is invalid; Nested exception is org.xml.sax.SAXParseException; Linenumber:12; columnnumber:29; Cvc-complex-type.2.4.c:the matching wildcard is strict, but no declaration can be found for element ' Aop:aspectj-autoprox
Y '. Org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:Line in XML document from file [D:\IdeaWorks \privatebank_test\pbank-console\pbank-console-web\target\pbank-console-web-1.0.0\web-inf\classes\config\spring \applicationcontext.xml] is invalid; Nested exception is org.xml.sax.SAXParseException; Linenumber:12; columnnumber:29; Cvc-complex-type.2.4.c:the matching wildcard is strict, but no declaration can be found for element ' Aop:aspectj-autoprox
Y '. At Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions ( Xmlbeandefinitionreader.java:3(+) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions ( xmlbeandefinitionreader.java:334) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions (Xmlbeandefinitionreader.java : 302) at Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( abstractbeandefinitionreader.java:174) at Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( abstractbeandefinitionreader.java:209) at Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( abstractbeandefinitionreader.java:180) at Net.paoding.rose.load.context.RoseWebAppContext.loadBeanDefinitions ( ROSEWEBAPPCONTEXT.JAVA:90) at Org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions ( xmlwebapplicationcontext.java:94) at Org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory ( Abstractrefreshableapplicationcontext.java:130) at Org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory ( abstractapplicationcontext.java:537) at Org.springframework.context.support.AbstractApplicationContext.refresh ( abstractapplicationcontext.java:451) at Net.paoding.rose.RoseFilter.prepareRootApplicationContext ( rosefilter.java:426) at Net.paoding.rose.RoseFilter.initFilterBean (rosefilter.java:268) at Org.springframework.web.filter.GenericFilterBean.init (genericfilterbean.java:194) at Org.apache.catalina.core.ApplicationFilterConfig.initFilter (applicationfilterconfig.java:279) at Org.apache.catalina.core.ApplicationFilterConfig.getFilter (applicationfilterconfig.java:260) at Org.apache.catalina.core.applicationfilterconfig.<init> (applicationfilterconfig.java:105) at Org.apache.catalina.core.StandardContext.filterStart (standardcontext.java:4958) at Org.apache.catalina.core.StandardContext.startInternal (standardcontext.java:5652) at Org.apache.catalina.util.LifecycleBase.staRT (lifecyclebase.java:145) at Org.apache.catalina.core.ContainerBase.addChildInternal (containerbase.java:899) at Org.apache.catalina.core.ContainerBase.addChild (containerbase.java:875) at Org.apache.catalina.core.StandardHost.addChild (standardhost.java:652) at ORG.APACHE.CATALINA.STARTUP.HOSTCONFIG.MANAGEAPP (hostconfig.java:1863) at SUN.REFLECT.NATIVEMETHODACCESSORIMPL.INVOKE0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke ( nativemethodaccessorimpl.java:57) at Sun.reflect.DelegatingMethodAccessorImpl.invoke ( delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (method.java:606) at Org.apache.tomcat.util.modeler.BaseModelMBean.invoke (basemodelmbean.java:301) at Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke (defaultmbeanserverinterceptor.java:819) at Com.sun.jmx.mbeanserver.JmxMBeanServer.invoke (jmxmbeanserver.java:801) at Org.apache.catalina.mbeans.MBeanFactory.createStandardContext (mbeanfactory.java:618) at Org.apache.catalina.Mbeans. Mbeanfactory.createstandardcontext (mbeanfactory.java:565) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (nativemethodaccessorimpl.java:57) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (method.java:606) at Org.apache.tomcat.util.modeler.BaseModelMBean.invoke ( basemodelmbean.java:301) at Com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke ( defaultmbeanserverinterceptor.java:819) at Com.sun.jmx.mbeanserver.JmxMBeanServer.invoke (jmxmbeanserver.java:801 ) at Javax.management.remote.rmi.RMIConnectionImpl.doOperation (rmiconnectionimpl.java:1487) at javax.management.remote.rmi.rmiconnectionimpl.access$300 (rmiconnectionimpl.java:97) at Javax.management.remote.rmi.rmiconnectionimpl$privilegedoperation.run (rmiconnectionimpl.java:1328) at
Javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation (rmiconnectionimpl.java:1420)At Javax.management.remote.rmi.RMIConnectionImpl.invoke (rmiconnectionimpl.java:848) at SUN.REFLECT.NATIVEMETHODACCESSORIMPL.INVOKE0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke ( nativemethodaccessorimpl.java:57) at Sun.reflect.DelegatingMethodAccessorImpl.invoke ( delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (method.java:606) at Sun.rmi.server.UnicastServerRef.dispatch (unicastserverref.java:322) at Sun.rmi.transport.transport$2.run ( transport.java:202) at Sun.rmi.transport.transport$2.run (transport.java:199) at Java.security.AccessController.doPrivileged (Native Method) at Sun.rmi.transport.Transport.serviceCall ( transport.java:198) at Sun.rmi.transport.tcp.TCPTransport.handleMessages (tcptransport.java:567) at Sun.rmi.transport.tcp.tcptransport$connectionhandler.run0 (tcptransport.java:828) at sun.rmi.transport.tcp.tcptransport$connectionhandler.access$400 (tcptransport.java:619) at Sun.rmi.transport.tcp.tcptransport$connectionhandler$1.Run (tcptransport.java:684) at Sun.rmi.transport.tcp.tcptransport$connectionhandler$1.run (TCPTransport.java:681) At java.security.AccessController.doPrivileged (Native Method) at sun.rmi.transport.tcp.tcptransport$ Connectionhandler.run (tcptransport.java:681) at Java.util.concurrent.ThreadPoolExecutor.runWorker (
threadpoolexecutor.java:1145) at Java.util.concurrent.threadpoolexecutor$worker.run (ThreadPoolExecutor.java:615) At Java.lang.Thread.run (thread.java:745) caused by:org.xml.sax.SAXParseException; Linenumber:12; columnnumber:29; Cvc-complex-type.2.4.c:the matching wildcard is strict, but no declaration can be found for element ' Aop:aspectj-autoprox
Y '. At Org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException (Unknown Source) at Org.apache.xerces.util.ErrorHandlerWrapper.error (Unknown Source) at Org.apache.xerces.impl.XMLErrorReporter.reportError (Unknown Source) at Org.apache.xerces.impl.XMLErrorReporter.reportError (Unknown Source) at org.apache.xerces.impl.xS.xmlschemavalidator$xsierrorreporter.reporterror (Unknown Source) at Org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError (Unknown Source) at Org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement (Unknown Source) at Org.apache.xerces.impl.xs.XMLSchemaValidator.emptyElement (Unknown Source) at Org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement (Unknown Source) at Org.apache.xerces.impl.xmldocumentfragmentscannerimpl$fragmentcontentdispatcher.dispatch (Unknown Source) at Org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument (Unknown Source) at Org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source) at Org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source) at Org.apache.xerces.parsers.XMLParser.parse ( Unknown source) at Org.apache.xerces.parsers.DOMParser.parse (Unknown source) at Org.apache.xerces.jaxp.DocumentBuilderImpl.parse (Unknown Source) at Org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocumENT (defaultdocumentloader.java:75) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions ( xmlbeandefinitionreader.java:388) ... More
The reason is that schemalocation lacks an AOP-related xsd configuration that resolves the issue after new AOP configuration is added to the XML file.
Modified as follows
<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:context= "Http://www.springframework.org/schema/context"
xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-2.5.xsd
HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP
Http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "
Default-lazy-init= "true" >
<context:annotation-config/>
<context:component-scan base-package= "Com.xyzq"/>
<aop:aspectj-autoproxy proxy-target-class= "false"/>
<bean name= "Bartplaceholderconfigurer" class= "Com.xyzq.simpson.bart.client.spring.BartPlaceholderConfigurer" >
<property name= "Location" value= "Classpath:config/app.properties"/>
</bean>
</beans>
Restart the program to start normally.