{"id":4505,"date":"2018-05-23T10:04:03","date_gmt":"2018-05-23T04:34:03","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=4505"},"modified":"2018-05-23T10:04:03","modified_gmt":"2018-05-23T04:34:03","slug":"spring-aop-aspect-oriented-programming","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/","title":{"rendered":"Spring AOP (Aspect Oriented Programming)"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><strong>AOP framework<\/strong> is one of the key components of the Spring framework. AOP provides a facility to enable middleware services with the Spring application in a loosely coupled manner. Middleware services are the additional services that makes our application to be executed in a stable manner in all the situations. Middleware services can be like transaction management, security, mailing, logging etc.<\/p>\n<p>By using <strong>Spring AOP<\/strong>, we can write the actual application and middleware services codes separately and then we can link these both codes through any of the AOP\u2019s implementation approaches (<em>programmatic, declarative XML, annotations<\/em>). The main aim of AOP is to separating services from the actual business code. In simple words, you can add some more functionality to your business code without writing anything extra in your actual code.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-4509\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Controller-300x147.png\" alt=\"\" width=\"502\" height=\"246\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Controller-300x147.png 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Controller-768x376.png 768w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Controller-624x305.png 624w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Controller.png 910w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><\/p>\n<h3>AOP Terminologies :<\/h3>\n<p>These are some central AOP concepts and terminologies. These terms are not spring specific but they are related to AOP.<\/p>\n<p><strong>&#8211; Aspect :<\/strong> It is the service class which contains advices, join points etc. For example, a logging module would be known as AOP aspect for logging. An application may have any number of aspects as per the requirement.<\/p>\n<p><strong>&#8211; Join point :<\/strong> It is the possible position in your business method where the advice can be applied. This point can be execution of a method or handling of an exception.<\/p>\n<p><strong>&#8211; Advice :<\/strong> This is the actual code which is invoked during the method execution either before or after by Spring AOP framework.<\/p>\n<p><strong>&#8211; Pointcut :<\/strong> It is a point or a condition to execute aspects for business methods by linking the advice with the join points.<\/p>\n<p><strong>&#8211; Introduction :<\/strong> It allows you to introduce new additional methods or attributes to the existing classes.<\/p>\n<p><strong>&#8211; Target Object :<\/strong> It is the object on which we will apply the services. It will always be a proxied object.<\/p>\n<p><strong>&#8211; AOP Proxy :<\/strong> If you add business along with your service, it will combine these both and finally delivers a proxy object which will always be a child object of business class.<\/p>\n<p><img decoding=\"async\" class=\" wp-image-4516 aligncenter\" src=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Proxy-300x146.png\" alt=\"\" width=\"513\" height=\"249\" srcset=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Proxy-300x146.png 300w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Proxy-768x375.png 768w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Proxy-624x304.png 624w, https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Proxy.png 910w\" sizes=\"(max-width: 513px) 100vw, 513px\" \/><\/p>\n<p><strong>&#8211; Weaving :<\/strong> Weaving means combining, it combines both your service and business at runtime in Spring AOP.<\/p>\n<p><strong>&#8211; Advisor :<\/strong> It is the combination of pointcut and advice.<\/p>\n<h3>Types of Advice :<\/h3>\n<p>These are different types of advices :<\/p>\n<p><strong>&#8211; Before advice :<\/strong> It executes before the method execution.<\/p>\n<p><strong>&#8211; After returning advice :<\/strong> It executes after the method execution only if method completes successfully.<\/p>\n<p><strong>&#8211; After throwing advice :<\/strong> It executes after the method execution only if method exits by throwing an exception.<\/p>\n<p><strong>&#8211; After (finally) advice :<\/strong> It executes after the method execution irrespective of it\u2019s termination either normally or abnormally.<\/p>\n<p><strong>&#8211; Around advice :<\/strong> It executes before and after of the advised method execution.<\/p>\n<p>Now let\u2019s try to understand Spring AOP by a simple example of logging. For better understanding, we will use Spring dtd based AOP implementation which will be a programmatic approach with XML configuration.<\/p>\n<h3>Required JARs :<\/h3>\n<h4>&#8211; AOP libraries<\/h4>\n<p style=\"text-align: left;\">\u00a0 \u00a0 \u00a0 \u00a0<strong>~<\/strong> spring-aop<br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0~<\/strong> spring-aspects<br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0~<\/strong> aspectj<br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0~<\/strong> aspectjrt<br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0~<\/strong> aspectjweaver<br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0~<\/strong> aopalliance<br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0~<\/strong> cglib-nodep<\/p>\n<p style=\"text-align: left;\"><span style=\"font-size: 1rem;\"><strong>&#8211; Other libraries :<\/strong><\/span><\/p>\n<p style=\"text-align: left;\">\u00a0 \u00a0 \u00a0 \u00a0<strong>~<\/strong> spring-core<br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0~<\/strong> spring-context<br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0~<\/strong> spring-beans<br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0~<\/strong> commons-logging<br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0~<\/strong> spring-expression<\/p>\n<p>Create a <strong>Bank<\/strong> <em>class<\/em> under <strong>business<\/strong> <em>package\u00a0<\/em>in which there will be two simple methods defined.<\/p>\n<pre class=\"lang:java decode:true\">package business;\r\n\r\npublic class Bank\r\n{\r\n\tprivate int amount = 10000;\r\n\tprivate String accountNo = \"bank001163\";\r\n\t\r\n\t\/\/1st method\r\n\tpublic int balanceDeposite(String accountNumber, int amountDeposite)\r\n\t{\r\n\t\tSystem.out.println(\"we are in balanceDeposite() method !!\");\r\n\t\tif (accountNumber.equalsIgnoreCase(this.accountNo))\r\n\t\t{\t\r\n\t\t\tthis.amount = this.amount + amountDeposite;\r\n\t\t\treturn this.amount;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tthrow new InvalidAccountException();\r\n\t\t}\r\n\t}\r\n\t\/\/2nd method\r\n\tpublic int getBalance(String accountNumber)\r\n\t{\r\n\t\tSystem.out.println(\"we are in getBalance() method !!\");\r\n\t\tif (accountNumber.equalsIgnoreCase(this.accountNo))\r\n\t\t{\r\n\t\t\treturn this.amount;\r\n\t\t}\r\n\t\telse \r\n\t\t{\r\n\t\t\tthrow new InvalidAccountException();\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<p>Define a customized exception for the Bank class within the same package,\u00a0<strong>InvalidAccountException<\/strong> <em>class<\/em>.<\/p>\n<pre class=\"lang:java decode:true \">package business;\r\n\r\npublic class InvalidAccountException extends RuntimeException\r\n{\r\n\t@Override\r\n\tpublic String toString()\r\n\t{\r\n\t\treturn \"Please check your a\/c number !!\";\r\n\t}\r\n}<\/pre>\n<p>Now, create <em>advice <\/em>&amp;<em> pointcut classes<\/em> under <strong>services<\/strong> <em>package<\/em>.<\/p>\n<p><strong>BeforeService.java &gt;&gt;\u00a0<\/strong>This will log an information before the method executes.<\/p>\n<pre class=\"lang:java decode:true\">package services;\r\n\r\nimport java.lang.reflect.Method;\r\n\r\nimport org.apache.commons.logging.Log;\r\nimport org.apache.commons.logging.LogFactory;\r\nimport org.springframework.aop.MethodBeforeAdvice;\r\n\r\nimport business.Bank;\r\n\r\npublic class BeforeService implements MethodBeforeAdvice\r\n{\r\n\t@Override\r\n\tpublic void before(Method m, Object[] params, Object o) throws Throwable\r\n\t{\r\n\t\tLog l = LogFactory.getLog(Bank.class);\r\n\t\tl.info(\"balanceDeposite() method : start || (BeforeService)\");\r\n\t}\r\n}<\/pre>\n<p><strong>AfterService.java &gt;&gt;\u00a0<\/strong>This will log an information after the method executes successfully.<\/p>\n<pre class=\"lang:java decode:true \">package services;\r\n\r\nimport java.lang.reflect.Method;\r\n\r\nimport org.apache.commons.logging.Log;\r\nimport org.apache.commons.logging.LogFactory;\r\nimport org.springframework.aop.AfterReturningAdvice;\r\n\r\nimport business.Bank;\r\n\r\npublic class AfterService implements AfterReturningAdvice\r\n{\r\n\t@Override\r\n\tpublic void afterReturning(Object returnValue, Method m, Object[] params, Object o) throws Throwable\r\n\t{\r\n\t\tLog l = LogFactory.getLog(Bank.class);\r\n\t\tl.info(\"balanceDeposite() method : end || (balance = \" + returnValue.toString() + \") || (AfterService)\");\r\n\t\t\/\/'returnValue' is the value returned by 'balanceDeposite()' method.\r\n\t}\r\n}<\/pre>\n<p><strong>AroundService.java &gt;&gt;\u00a0<\/strong>This will log informations before and after the method executes.<\/p>\n<pre class=\"lang:java decode:true \">package services;\r\n\r\nimport org.apache.commons.logging.Log;\r\nimport org.apache.commons.logging.LogFactory;\r\nimport org.aopalliance.intercept.MethodInterceptor;\r\nimport org.aopalliance.intercept.MethodInvocation;\r\n\r\nimport business.Bank;\r\n\r\npublic class AroundService implements MethodInterceptor\r\n{\r\n\t@Override\r\n\tpublic Object invoke(MethodInvocation mi) throws Throwable\r\n\t{\r\n\t\tLog l = LogFactory.getLog(Bank.class);\r\n\t\tl.info(\"balanceDeposite() method : start || (AroundService)\");\t\t\/\/line 16\r\n\t\t\r\n\t\tObject returnObject = mi.proceed();\t\t\t\t\t\t\t\t\t\/\/line 18\r\n\t\t\/*\r\n\t\tline 18 will execute first line 16 then 'balanceDeposite()' method \r\n\t\tand at the end it will execute line 25.\r\n\t\t'returnObject' is the value in the form of an object returned by 'balanceDeposite()' method which was an integer.\r\n\t\t*\/\r\n\t\t\r\n\t\tl.info(\"balanceDeposite() method : end || (AroundService)\");\t\t\t\/\/line 25\r\n\t\t\r\n\t\treturn returnObject;\r\n\t}\r\n}<\/pre>\n<p><strong>ThrowsService.java &gt;&gt;\u00a0<\/strong>This will log an information along with the exception message if any exception occur in method execution.<\/p>\n<pre class=\"lang:java decode:true \">package services;\r\n\r\nimport org.apache.commons.logging.Log;\r\nimport org.apache.commons.logging.LogFactory;\r\nimport org.springframework.aop.ThrowsAdvice;\r\n\r\nimport business.Bank;\r\n\r\npublic class ThrowsService implements ThrowsAdvice\r\n{\r\n\t\/*\r\n\t'ThrowsAdvice' interface contains five methods. And it doesn't forces you to implement any of it's method.\r\n\tat runtime our proxy will add all these five methods.\r\n\tfrom these five methods, if you are providing any of it's implementation, then our proxy will not provide that particular method's implementation.\r\n\t*\/\r\n\r\n\t\/\/this method will execute iff any exception raised in our 'balanceDeposite()' method. \r\n\tpublic void afterThrowing(Exception e) throws Throwable\r\n\t{\r\n\t\tLog l = LogFactory.getLog(Bank.class);\r\n\t\tl.error(\"exception raised in balanceDeposite() method || (\" + e.toString() + \")\");\r\n\t}\r\n}<\/pre>\n<p>If we will apply these services to our business without any condition, in such case these all services will execute for each method of the Bank class. But we want to execute services only for some methods. For doing this we have to use <em>pointcut classes <\/em>along with the <em>advice<\/em> in <em>advisors<\/em>.<\/p>\n<p><strong>PointcutForDeposite.java &gt;&gt;\u00a0<\/strong>This will put a condition to the services to execute only for &#8216;balanceDeposite()&#8217; method.<\/p>\n<pre class=\"lang:java decode:true \">package services;\r\n\r\nimport java.lang.reflect.Method;\r\n\r\nimport org.springframework.aop.support.StaticMethodMatcherPointcut;\r\n\r\npublic class PointcutForDeposite extends StaticMethodMatcherPointcut\r\n{\r\n\t@Override\r\n\tpublic boolean matches(Method m, Class c)\r\n\t{\r\n\t\t\/*\r\n\t\tthis 'matches()' method will check here the required method's name for which we want to execute a service.\r\n\t\tif the method name is correct then it returns TRUE else returns FALSE.\r\n\t\t*\/\r\n\t\t\r\n\t\tString methodName = m.getName();\r\n\t\t\r\n\t\tif (methodName.equalsIgnoreCase(\"balanceDeposite\"))\r\n\t\t{\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\t\r\n\t}\r\n}<\/pre>\n<p>Now, come to the main <em>XML configuration file<\/em> (<strong>spring.xml<\/strong> in <strong>resources<\/strong> <em>package<\/em>).<\/p>\n<pre class=\"lang:xhtml decode:true \">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n\r\n&lt;!DOCTYPE beans PUBLIC \"-\/\/SPRING\/\/DTD BEAN 2.0\/\/EN\" \r\n\t\t\t\"http:\/\/www.springframework.org\/dtd\/spring-beans-2.0.dtd\"&gt;\r\n\r\n&lt;beans&gt;\r\n\r\n\t&lt;bean id = \"bank\" class = \"business.Bank\" \/&gt;\t\t\t\t&lt;!-- target --&gt;\r\n\t&lt;bean id = \"bfs\" class = \"services.BeforeService\" \/&gt;\t\t&lt;!-- before advice --&gt;\r\n\t&lt;bean id = \"afs\" class = \"services.AfterService\" \/&gt;\t\t&lt;!-- after advice --&gt;\r\n\t&lt;bean id = \"ars\" class = \"services.AroundService\" \/&gt;\t\t&lt;!-- around advice --&gt;\r\n\t&lt;bean id = \"ts\" class = \"services.ThrowsService\" \/&gt;\t\t&lt;!-- throws advice --&gt;\r\n\t\r\n\t&lt;bean id = \"pfd\" class = \"services.PointcutForDeposite\" \/&gt;\t&lt;!-- pointcut (condition) --&gt;\r\n\t\r\n\t&lt;!-- in lines 17-21, we are allowing around advice to execute only for 'balanceDeposite()' method --&gt;\r\n\t&lt;bean id = \"dpa\" class = \"org.springframework.aop.support.DefaultPointcutAdvisor\"&gt;\t&lt;!-- default advisor class --&gt;\r\n\t&lt;!-- in this class we have setter methods for service &amp; pointcut --&gt;\r\n\t\t&lt;property name = \"advice\" ref = \"ars\" \/&gt;\t\t\t\t&lt;!-- set advice --&gt;\r\n\t\t&lt;property name = \"pointcut\" ref = \"pfd\" \/&gt;\t\t\t\t&lt;!-- set pointcut --&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id = \"pfb\" class = \"org.springframework.aop.framework.ProxyFactoryBean\"&gt;\t&lt;!-- proxy --&gt;\r\n\t\t&lt;property name = \"target\" ref = \"bank\" \/&gt;\t\t\t\t&lt;!-- set target --&gt;\r\n\t\t&lt;property name = \"interceptorNames\"&gt;\t\t\t\t\t&lt;!-- adding advices\/advisors --&gt;\r\n\t\t\t&lt;list&gt;\t\t\t\t\t\t\t\t\t\t\t\t&lt;!-- passing string type array of advices\/advisors --&gt;\r\n\t\t\t\t&lt;value&gt;bfs&lt;\/value&gt;\r\n\t\t\t\t&lt;value&gt;afs&lt;\/value&gt;\r\n\t\t\t\t&lt;!-- &lt;value&gt;ars&lt;\/value&gt; --&gt;\t\t\t\t\t\t&lt;!-- line 28 || in this case, around advice will execute for all methods --&gt;\r\n\t\t\t\t&lt;value&gt;dpa&lt;\/value&gt;\t\t\t\t\t\t\t\t&lt;!-- line 29 || around advice will execute only for 'balanceDeposite()' method --&gt;\r\n\t\t\t\t&lt;value&gt;ts&lt;\/value&gt;\r\n\t\t\t&lt;\/list&gt;\r\n\t\t&lt;\/property&gt;\r\n\t&lt;\/bean&gt;\r\n\r\n&lt;\/beans&gt;<\/pre>\n<p>Finally create a test <em>class<\/em>\u00a0<strong>Client.java<\/strong> under <strong>client<\/strong> <em>package<\/em>.<\/p>\n<pre class=\"lang:java decode:true \">package client;\r\n\r\nimport org.springframework.context.ConfigurableApplicationContext;\r\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\r\n\r\nimport business.Bank;\r\n\r\npublic class Client\r\n{\r\n\tpublic static void main(String[] args)\r\n\t{\t\r\n\t\t\/\/load proxy into container\r\n\t\tConfigurableApplicationContext cap = new ClassPathXmlApplicationContext(\"resources\/spring.xml\");\r\n\t\t\r\n\t\t\/\/get generated proxy object\r\n\t\tBank bProxy = (Bank) cap.getBean(\"pfb\");\r\n\t\t\/*\r\n\t\t'pfb' is a factory bean, and factory bean always needs to return other class's object. \r\n\t\there it returns Bank class's object.\r\n\t\t*\/\r\n\r\n\t\tint accountBalance = bProxy.balanceDeposite(\"bank001163\", 7000);\t\t\t\/\/line 22\r\n\t\tSystem.out.println(\"your account balance is : \" + accountBalance);\t\t\t\/\/line 23\r\n\t\t\r\n\/\/\t\tint accountBalance = bProxy.getBalance(\"bank001163\");\t\t\t\t\t\t\/\/line 25\r\n\/\/\t\tSystem.out.println(\"your account balance is : \" + accountBalance);\t\t\t\/\/line 26\r\n\r\n\t\tcap.close(); \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\/\/closing container.\r\n\t}\r\n}<\/pre>\n<p>The outputs for this example will be like :<\/p>\n<pre class=\"lang:default decode:true \">\/\/ 1. Before, After &amp; Around services executes for 'balanceDeposite()' method.\r\n\r\nINFO: balanceDeposite() method : start || (BeforeService)\r\nINFO: balanceDeposite() method : start || (AroundService)\r\nwe are in balanceDeposite() method !!\r\nINFO: balanceDeposite() method : end || (AroundService)\r\nINFO: balanceDeposite() method : end || (balance = 17000) || (AfterService)\r\nyour account balance is : 17000\r\n\r\n\/\/ 2. If we pass a wrong a\/c no. from Client.java to 'balanceDeposite()' method, Throws advice will execute for 'balanceDeposite()' method.\r\n\r\nINFO: balanceDeposite() method : start || (BeforeService)\r\nINFO: balanceDeposite() method : start || (AroundService)\r\nwe are in balanceDeposite() method !!\r\nSEVERE: exception raised in balanceDeposite() method || (Please check your a\/c number !!)\r\n\r\n\/\/ 3. If we comment line 22, 23 and uncomment line 25, 26; Before &amp; After services executes for 'getBalance()' method, Around service will not execute because we put a pointcut in our example for this advice.\r\n\r\nINFO: balanceDeposite() method : start || (BeforeService)\r\nwe are in getBalance() method !!\r\nINFO: balanceDeposite() method : end || (balance = 10000) || (AfterService)\r\nyour account balance is : 10000<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; AOP framework is one of the key components of the Spring framework. AOP provides a facility to enable middleware services with the Spring application in a loosely coupled manner. Middleware services are the additional services that makes our application to be executed in a stable manner in all the situations. Middleware services can be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4507,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[256,102],"tags":[224,268,243,267],"class_list":["post-4505","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-application","category-web-service","tag-java","tag-loose-coupling","tag-spring","tag-spring-aop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring AOP (Aspect Oriented Programming) - InnovationM - Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring AOP (Aspect Oriented Programming) - InnovationM - Blog\" \/>\n<meta property=\"og:description\" content=\"&nbsp; AOP framework is one of the key components of the Spring framework. AOP provides a facility to enable middleware services with the Spring application in a loosely coupled manner. Middleware services are the additional services that makes our application to be executed in a stable manner in all the situations. Middleware services can be [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-23T04:34:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Banner.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1140\" \/>\n\t<meta property=\"og:image:height\" content=\"487\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Spring AOP (Aspect Oriented Programming)\",\"datePublished\":\"2018-05-23T04:34:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/\"},\"wordCount\":709,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/05\\\/Spring-AOP-Banner.png\",\"keywords\":[\"java\",\"loose coupling\",\"Spring\",\"Spring AOP\"],\"articleSection\":[\"Java Application\",\"Web service\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/\",\"name\":\"Spring AOP (Aspect Oriented Programming) - InnovationM - Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/05\\\/Spring-AOP-Banner.png\",\"datePublished\":\"2018-05-23T04:34:03+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/05\\\/Spring-AOP-Banner.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/05\\\/Spring-AOP-Banner.png\",\"width\":1140,\"height\":487},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/spring-aop-aspect-oriented-programming\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring AOP (Aspect Oriented Programming)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring AOP (Aspect Oriented Programming) - InnovationM - Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/","og_locale":"en_US","og_type":"article","og_title":"Spring AOP (Aspect Oriented Programming) - InnovationM - Blog","og_description":"&nbsp; AOP framework is one of the key components of the Spring framework. AOP provides a facility to enable middleware services with the Spring application in a loosely coupled manner. Middleware services are the additional services that makes our application to be executed in a stable manner in all the situations. Middleware services can be [&hellip;]","og_url":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/","og_site_name":"InnovationM - Blog","article_published_time":"2018-05-23T04:34:03+00:00","og_image":[{"width":1140,"height":487,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Banner.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Spring AOP (Aspect Oriented Programming)","datePublished":"2018-05-23T04:34:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/"},"wordCount":709,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Banner.png","keywords":["java","loose coupling","Spring","Spring AOP"],"articleSection":["Java Application","Web service"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/","url":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/","name":"Spring AOP (Aspect Oriented Programming) - InnovationM - Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Banner.png","datePublished":"2018-05-23T04:34:03+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Banner.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2018\/05\/Spring-AOP-Banner.png","width":1140,"height":487},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/spring-aop-aspect-oriented-programming\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Spring AOP (Aspect Oriented Programming)"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/4505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=4505"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/4505\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/4507"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=4505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=4505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=4505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}