{"id":5629,"date":"2013-08-26T22:46:52","date_gmt":"2013-08-26T19:46:52","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=5629"},"modified":"2019-02-19T15:28:35","modified_gmt":"2019-02-19T13:28:35","slug":"spring-aop-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/","title":{"rendered":"Spring AOP Example"},"content":{"rendered":"<p>With this tutorial we shall show you how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide declarative enterprise services, especially as a replacement for EJB declarative services. It is also used to allow users to implement custom aspects, complementing their use of OOP with AOP.<\/p>\n<p>We will demonstrate how to create and apply some central AOP concepts. In short we will create all types of advices, we will use a pointcut and an advisor over an advice and we will check on some special features of Spring in interceptors and proxy beans.<\/p>\n<p>Our preferred development environment is <a href=\"http:\/\/www.eclipse.org\/\" target=\"_blank\">Eclipse<\/a>. We are using Eclipse Juno (4.2) version, along with <a href=\"http:\/\/maven.apache.org\/\" target=\"_blank\">Maven<\/a> Integration plugin version 3.1.0. You can download Eclipse from <a href=\"http:\/\/www.eclipse.org\/downloads\/\" target=\"_blank\">here<\/a> and Maven Plugin for Eclipse from <a href=\"http:\/\/maven.apache.org\/eclipse-plugin.html\" target=\"_blank\">here<\/a>. The installation of Maven plugin for Eclipse is out of the scope of this tutorial and will not be discussed. We are also using Spring version 3.2.3 and the JDK 7_u_21.<\/p>\n<p>Let&#8217;s begin.\n<\/p>\n<h2>1. Create a new Maven project<\/h2>\n<p>Go to File -&gt; Project -&gt;Maven -&gt; Maven Project.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/New-Maven-Project.png\"><img decoding=\"async\" width=\"521\" height=\"504\" class=\"alignnone size-medium wp-image-4341\" alt=\"New-Maven-Project\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/New-Maven-Project.png\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/New-Maven-Project.png 521w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/New-Maven-Project-300x290.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/New-Maven-Project-42x42.png 42w\" sizes=\"(max-width: 521px) 100vw, 521px\" \/><\/a><\/p>\n<p>In the &#8220;Select project name and location&#8221; page of the wizard, make sure that &#8220;Create a simple project (skip archetype selection)&#8221; option is <strong>checked<\/strong>, hit &#8220;Next&#8221; to continue with default values.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Maven-Project-Name-Location.png\"><img decoding=\"async\" width=\"603\" height=\"550\" class=\"alignnone size-medium wp-image-4342\" alt=\"Maven-Project-Name-Location\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Maven-Project-Name-Location.png\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Maven-Project-Name-Location.png 603w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Maven-Project-Name-Location-300x273.png 300w\" sizes=\"(max-width: 603px) 100vw, 603px\" \/><\/a><\/p>\n<p>In the &#8220;Enter an artifact id&#8221; page of the wizard, you can define the name and main package of your project. We will set the &#8220;Group Id&#8221; variable to <code>\"com.javacodegeeks.snippets.enterprise\"<\/code> and the &#8220;Artifact Id&#8221; variable to <code>\"springexample\"<\/code>. The aforementioned selections compose the main project package as <code>\"com.javacodegeeks.snippets.enterprise.springexample\"<\/code> and the project name as <code>\"springexample\"<\/code>. Hit &#8220;Finish&#8221; to exit the wizard and to create your project.<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Configure-Maven-Project.jpg\"><img decoding=\"async\" width=\"603\" height=\"552\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Configure-Maven-Project.jpg\" alt=\"Configure-Maven-Project\" class=\"alignnone size-medium wp-image-4373\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Configure-Maven-Project.jpg 603w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Configure-Maven-Project-300x274.jpg 300w\" sizes=\"(max-width: 603px) 100vw, 603px\" \/><\/a><\/p>\n<p>The Maven project structure is shown below:<\/p>\n<p><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Maven-project-structure.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Maven-project-structure.jpg\" alt=\"Maven-project-structure\" width=\"493\" height=\"396\" class=\"alignnone size-full wp-image-4376\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Maven-project-structure.jpg 493w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Maven-project-structure-300x240.jpg 300w\" sizes=\"(max-width: 493px) 100vw, 493px\" \/><\/a><\/p>\n<ul>It consists of the following folders:<\/p>\n<li>\/src\/main\/java folder, that contains source files for the dynamic content of the application,<\/li>\n<li>\/src\/test\/java folder contains all source files for unit tests,<\/li>\n<li>\/src\/main\/resources folder contains configurations files,<\/li>\n<li>\/target folder contains the compiled and packaged deliverables,<\/li>\n<li>the pom.xml is the project object model (POM) file. The single file that contains all project related configuration.<\/li>\n<\/ul>\n<h2>2. Add Spring 3.2.3 dependency<\/h2>\n<ul>\n<li>Locate the &#8220;Properties&#8221; section at the &#8220;Overview&#8221; page of the POM editor and perform the following changes:<br \/>\nCreate a new property with name <strong>org.springframework.version<\/strong> and value <strong>3.2.3.RELEASE<\/strong>.<\/li>\n<li>Navigate to the &#8220;Dependencies&#8221; page of the POM editor and create the following dependencies (you should fill the &#8220;GroupId&#8221;, &#8220;Artifact Id&#8221; and &#8220;Version&#8221; fields of the &#8220;Dependency Details&#8221; section at that page):<br \/>\nGroup Id : <strong>org.springframework<\/strong> Artifact Id : <strong>spring-web<\/strong> Version : <strong>${org.springframework.version}<\/strong><\/li>\n<\/ul>\n<p>Alternatively, you can add the Spring dependencies in Maven\u2019s <code>pom.xml<\/code> file, by directly editing it at the &#8220;Pom.xml&#8221; page of the POM editor, as shown below:<br \/>\n&nbsp;<br \/>\n<span style=\"text-decoration: underline;\"><em>pom.xml:<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\"; xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n\txsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n\t&lt;groupId&gt;com.javacodegeeks.snippets.enterprise&lt;\/groupId&gt;\n\t&lt;artifactId&gt;springexample&lt;\/artifactId&gt;\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n\n\t&lt;dependencies&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;spring-core&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;${spring.version}&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;spring-context&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;${spring.version}&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t&lt;\/dependencies&gt;\n\n\t&lt;properties&gt;\n\t\t&lt;spring.version&gt;3.2.3.RELEASE&lt;\/spring.version&gt;\n\t&lt;\/properties&gt;\n&lt;\/project&gt;\n<\/pre>\n<p>As you can see Maven manages library dependencies declaratively. A local repository is created (by default under {user_home}\/.m2 folder) and all required libraries are downloaded and placed there from public repositories. Furthermore intra \u2013 library dependencies are automatically resolved and manipulated.<\/p>\n<h2>3. Create an Advice<\/h2>\n<p>In AOP the Advice is an action taken before or after a method execution. There are different types of advice, such as &#8220;around,&#8221; &#8220;before&#8221; and &#8220;after&#8221; advice. Below we introduce all types of advice and create an example for each one of them.<\/p>\n<p><code>SimpleService.java<\/code> class is the class whose methods will be intercepted by the advices we will create.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SimpleService.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise;\n\npublic class SimpleService {\n\n\tprivate String name;\n\n\tprivate int id;\n\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\n\tpublic int getId() {\n\t\treturn id;\n\t}\n\n\tpublic void setId(int id) {\n\t\tthis.id = id;\n\t}\n\n\tpublic void printNameId() {\n\t\tSystem.out.println(\"SimpleService : Method printNameId() : My name is \" + name\n\t\t\t + \" and my id is \" + id);\n\t}\n\n\tpublic void checkName() {\n\t\tif (name.length() &lt; 20) {\n\t\t\tthrow new IllegalArgumentException();\n\t\t}\n\t}\n\n\tpublic void sayHello(String message){\n\t\tSystem.out.println(\"SimpleService : Method sayHello() : Hello! \" + message);\n\t}\n}\n<\/pre>\n<h3>3.1 Before Advice<\/h3>\n<p>Before Advice executes before a method execution, but does not have the ability to prevent execution flow proceeding to the method execution (unless it throws an exception). The class that implements it is the one below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em><\/em>DoBeforeMethod.java<\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.aop;\n\nimport java.lang.reflect.Method;\nimport org.springframework.aop.MethodBeforeAdvice;\n \npublic class DoBeforeMethod implements MethodBeforeAdvice\n{\n\tpublic void before(Method method, Object[] args, Object target)\n\t\tthrows Throwable {\n\t        System.out.println(\"****SPRING AOP**** DoBeforeMethod : Executing before method!\");\n\t}\n}\n<\/pre>\n<p>The advice bean must be defined in Spring configuration file. In addition, a proxy object must be created, of <code>ProxyFactoryBean<\/code> type. The proxy bean has a <code>target<\/code> property. Its value is a reference to the bean whose methods will be intercepted. It also has an <code>interceptorNames<\/code> property. The property value is a list of bean names that represent the advices that will be applied on this proxy \/target object.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"doBeforeMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoBeforeMethod\" \/&gt;\n\n\t&lt;bean id=\"simpleServiceProxy\" class=\"org.springframework.aop.framework.ProxyFactoryBean\"&gt;\n\t\t&lt;property name=\"target\" ref=\"simpleServiceBean\" \/&gt;\n\t\t&lt;property name=\"interceptorNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;doBeforeMethodBean&lt;\/value&gt;\n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t&lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/pre>\n<p>We must load the <code>simpleServiceProxy<\/code> bean in <code>App.class<\/code> in order to run the application, as shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>App.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise;\n\nimport org.springframework.context.ConfigurableApplicationContext;\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\n\npublic class App {\n\n\tpublic static void main(String[] args) {\n\t\n\t\t\tConfigurableApplicationContext context = new ClassPathXmlApplicationContext(\"applicationContext.xml\");\n\t\t\tSimpleService simpleService = (SimpleService) context.getBean(\"simpleServiceProxy\");\n\t\t\tsimpleService.printNameId();\n\t\t\tSystem.out.println(\"--------------\");\n\t\t\ttry{\n\t\t\t\tsimpleService.checkName();\n\t\t\t} catch(Exception e){\n\t\t\t\tSystem.out.println(\"SimpleService: Method checkName() exception thrown..\");\n\t\t\t}\n\t\t\tSystem.out.println(\"--------------\");\n\t\t\tsimpleService.sayHello(\"Javacodegeeks\");\n\t\t\tcontext.close();\n\t}\n}\n<\/pre>\n<p>As a result, the <code>before(Method method, Object[] args, Object target)<\/code> method of the <code>DoBeforeMethod<\/code> Advice is invoked before the <code>simpleService<\/code>&#8216;s methods execution.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code sty=\"\" le=\"color: black; word-wrap: normal;\">****SPRING AOP**** DoBeforeMethod : Executing before method!\nSimpleService : Method printNameId() : My name is Hello and my id is 12345 \n--------------\n****SPRING AOP**** DoBeforeMethod : Executing before method!\nSimpleService: Method checkName() exception thrown..\n--------------\n****SPRING AOP**** DoBeforeMethod : Executing before method!\nSimpleService : Method sayHello() : Hello! Javacodegeeks<\/code><\/pre>\n<h3>3.2 After Returning Advice<\/h3>\n<p>After returning advice is the Advice to be executed after a method execution completes normally: for example, if a method returns without throwing an exception. The class that implements it is the one below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em><\/em>DoAfterReturningMethod.java<\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.aop;\n\nimport java.lang.reflect.Method;\nimport org.springframework.aop.AfterReturningAdvice;\n\npublic class DoAfterReturningMethod implements AfterReturningAdvice {\n\tpublic void afterReturning(Object returnValue, Method method,\n\t\t\tObject[] args, Object target) throws Throwable {\n\t\tSystem.out.println(\"****SPRING AOP**** DoAfterReturningMethod : Executing after method return!\");\n\t}\n\n}<\/pre>\n<p>We add the new bean in <code>applicationContext.xml<\/code>, following the same steps as above.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml; highlight:[16,17,24]\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"doBeforeMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoBeforeMethod\" \/&gt;\n\n\t&lt;bean id=\"doAfterReturningMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoAfterReturningMethod\" \/&gt;\n\n\t&lt;bean id=\"simpleServiceProxy\" class=\"org.springframework.aop.framework.ProxyFactoryBean\"&gt;\n\t\t&lt;property name=\"target\" ref=\"simpleServiceBean\" \/&gt;\n\t\t&lt;property name=\"interceptorNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;doBeforeMethodBean&lt;\/value&gt;\n\t\t\t\t&lt;value&gt;doAfterReturningMethodBean&lt;\/value&gt;\n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t&lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/pre>\n<p>Now, after running <code>App.java<\/code> class again we can see that the <code>afterReturning(Object returnValue, Method method, Object[] args, Object target)<\/code> method of <code>DoAfterReturningMethod<\/code> advice is executed after the <code>simpleService<\/code>&#8216;s methods&#8217; execution. Note that since <code>checkName()<\/code> method throws an exception and does not return normally, it is not being intercepted by <code>DoAfterReturningMethod<\/code>.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code sty=\"\" le=\"color: black; word-wrap: normal;\">****SPRING AOP**** DoBeforeMethod : Executing before method!\nSimpleService : Method printNameId() : My name is Hello and my id is 12345\n****SPRING AOP**** DoAfterReturningMethod : Executing after method return!\n--------------\n****SPRING AOP**** DoBeforeMethod : Executing before method!\nSimpleService: Method checkName() exception thrown..\n--------------\n****SPRING AOP**** DoBeforeMethod : Executing before method!\nSimpleService : Method sayHello() : Hello! Javacodegeeks\n****SPRING AOP**** DoAfterReturningMethod : Executing after method return!<\/code><\/pre>\n<h3>3.3 After Throwing Advice<\/h3>\n<p>After throwing Advice is the Advice to be executed if a method exits by throwing an exception. The class that implements it in the example is the one shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em><\/em>DoAfterThrowingExceptionMethod.java<\/span><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.aop;\n\nimport org.springframework.aop.ThrowsAdvice;\n\npublic class DoAfterThrowingExceptionMethod implements ThrowsAdvice {\n\tpublic void afterThrowing(IllegalArgumentException e) throws Throwable {\n\t\tSystem.out.println(\"****SPRING AOP**** DoAfterThrowingExceptionMethod : Executing when method throws exception!\");\n\t}\n}\n<\/pre>\n<p>We add the new bean in <code>applicationContext.xml<\/code>.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml; highlight:[19,20,28]\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"doBeforeMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoBeforeMethod\" \/&gt;\n\n\t&lt;bean id=\"doAfterReturningMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoAfterReturningMethod\" \/&gt;\n\n&lt;bean id=\"doAfterThrowingExceptionMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoAfterThrowingExceptionMethod\" \/&gt;\n\n\t&lt;bean id=\"simpleServiceProxy\" class=\"org.springframework.aop.framework.ProxyFactoryBean\"&gt;\n\t\t&lt;property name=\"target\" ref=\"simpleServiceBean\" \/&gt;\n\t\t&lt;property name=\"interceptorNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;doBeforeMethodBean&lt;\/value&gt;\n\t\t\t\t&lt;value&gt;doAfterReturningMethodBean&lt;\/value&gt;\n\t\t\t\t&lt;value&gt;doAfterThrowingExceptionMethodBean&lt;\/value&gt;\n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t&lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/pre>\n<p>Now, after running the example again we can see that only the <code>checkName()<\/code> method is being intercepted by the <code>DoAfterThrowingExceptionMethod<\/code>.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code sty=\"\" le=\"color: black; word-wrap: normal;\">****SPRING AOP**** DoBeforeMethod : Executing before method!\nSimpleService : Method printNameId() : My name is Hello and my id is 12345\n****SPRING AOP**** DoAfterReturningMethod : Executing after method return!\n--------------\n****SPRING AOP**** DoBeforeMethod : Executing before method!\n****SPRING AOP**** DoAfterThrowingExceptionMethod : Executing when method throws exception!\nSimpleService: Method checkName() exception thrown..\n--------------\n****SPRING AOP**** DoBeforeMethod : Executing before method!\nSimpleService : Method sayHello() : Hello! Javacodegeeks\n****SPRING AOP**** DoAfterReturningMethod : Executing after method return!\n<\/code><\/pre>\n<h3>3.4 Around Advice<\/h3>\n<p>Around advice is the Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception. The class that implements an around Advice is shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em><\/em>DoAroundMethod.java<\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.aop;\n\n\timport java.util.Arrays;\n\t \n\timport org.aopalliance.intercept.MethodInterceptor;\n\timport org.aopalliance.intercept.MethodInvocation;\n\npublic class DoAroundMethod implements MethodInterceptor {\n\t\tpublic Object invoke(MethodInvocation methodInvocation) throws Throwable {\n\t \n\t\t\tSystem.out.println(\"****SPRING AOP**** DoAroundMethod: Method name : \"\n\t\t\t\t\t+ methodInvocation.getMethod().getName());\n\t\t\tSystem.out.println(\"****SPRING AOP**** DoAroundMethod: Method arguments : \"\n\t\t\t\t\t+ Arrays.toString(methodInvocation.getArguments()));\n\t\t\t\/\/ same with MethodBeforeAdvice\n\t\t\tSystem.out.println(\"****SPRING AOP**** DoAroundMethod: Before method executing!\");\n\t \n\t\t\ttry {\n\t\t\t\t\/\/ proceed to original method call\n\t\t\t\tObject result = methodInvocation.proceed();\n\t\t\t\t\/\/ same with AfterReturningAdvice\n\t\t\t\tSystem.out.println(\"****SPRING AOP**** DoAroundMethod: After method executing!\");\n\t\t\t\treturn result;\n\t \n\t\t\t} catch (IllegalArgumentException e) {\n\t\t\t\t\/\/ same with ThrowsAdvice\n\t\t\t\tSystem.out.println(\"****SPRING AOP**** DoAroundMethod: When method throws Exception!\");\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n}<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml; highlight:[22,23,32]\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"doBeforeMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoBeforeMethod\" \/&gt;\n\n\t&lt;bean id=\"doAfterReturningMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoAfterReturningMethod\" \/&gt;\n\n&lt;bean id=\"doAfterThrowingExceptionMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoAfterThrowingExceptionMethod\" \/&gt;\n\n&lt;bean id=\"doAroundMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoAroundMethod\" \/&gt;\n\n\t&lt;bean id=\"simpleServiceProxy\" class=\"org.springframework.aop.framework.ProxyFactoryBean\"&gt;\n\t\t&lt;property name=\"target\" ref=\"simpleServiceBean\" \/&gt;\n\t\t&lt;property name=\"interceptorNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;doBeforeMethodBean&lt;\/value&gt;\n\t\t\t\t&lt;value&gt;doAfterReturningMethodBean&lt;\/value&gt;\n\t\t\t\t&lt;value&gt;doAfterThrowingExceptionMethodBean&lt;\/value&gt;\n\t\t\t\t&lt;value&gt;doAroundMethodBean&lt;\/value&gt;\n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t&lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/pre>\n<p>When running the application with the <code>DoAroundMethod<\/code> advice we can see that it intercepts all methods of <code>simpleService<\/code>.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code sty=\"\" le=\"color: black; word-wrap: normal;\">****SPRING AOP**** DoBeforeMethod : Executing before method!\n****SPRING AOP**** DoAroundMethod: Method name : printNameId\n****SPRING AOP**** DoAroundMethod: Method arguments : []\n****SPRING AOP**** DoAroundMethod: Before method executing!\nSimpleService : Method printNameId() : My name is Hello and my id is 12345\n****SPRING AOP**** DoAroundMethod: After method executing!\n****SPRING AOP**** DoAfterReturningMethod : Executing after method return!\n--------------\n****SPRING AOP**** DoBeforeMethod : Executing before method!\n****SPRING AOP**** DoAroundMethod: Method name : checkName\n****SPRING AOP**** DoAroundMethod: Method arguments : []\n****SPRING AOP**** DoAroundMethod: Before method executing!\n****SPRING AOP**** DoAroundMethod: When method throws Exception!\n****SPRING AOP**** DoAfterThrowingExceptionMethod : Executing when method throws exception!\nSimpleService: Method checkName() exception thrown..\n--------------\n****SPRING AOP**** DoBeforeMethod : Executing before method!\n****SPRING AOP**** DoAroundMethod: Method name : sayHello\n****SPRING AOP**** DoAroundMethod: Method arguments : [Javacodegeeks]\n****SPRING AOP**** DoAroundMethod: Before method executing!\nSimpleService : Method sayHello() : Hello! Javacodegeeks\n****SPRING AOP**** DoAroundMethod: After method executing!\n****SPRING AOP**** DoAfterReturningMethod : Executing after method return!\n<\/code><\/pre>\n<h2>4. Create a Pointcut and an Advisor<\/h2>\n<p>The Pointcut indicates which method should be intercepted whereas the Advisor groups the Advice and the Pointcut into a single unit, and passes it to a proxy factory object.<\/p>\n<p>There are two types of Pointcuts, the ones that match a method by its name and the ones that match a method using a regular expression pattern. Let&#8217;s see how both types of Pointcuts can be used.<\/p>\n<h3>4.1 name match pointcut<\/h3>\n<p>In order to create a new Pointcut that will match a method by its name, we have to define it as a bean of <code>NameMatchMethodPointcut<\/code> type in <code>applicationContext.xml<\/code>. In its property <code>mappedName<\/code>, the value to be set is the name of the method that will be intercepted. Here, we will intercept <code>sayHello(String message)<\/code> method.<\/p>\n<p>We must also define the advisor as a bean of <code>DefaultPointcutAdvisor<\/code> type, here <code>simpleAdvisor<\/code> bean. Its properties are <code>pointcut<\/code> and <code>advice<\/code> and their values are references to the beans of the advice and the pointcut that will be used.<\/p>\n<p>Finally, in <code>simpleServiceProxy<\/code> bean we must replace the <code>doAroundMethodBean<\/code> value of <code>interceptorNames<\/code> property with the <code>simpleAdvisor<\/code>.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;highlight:[16,17,18,19,20,21,22,28]\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n&lt;bean id=\"doAroundMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoAroundMethod\" \/&gt;\n\n\t&lt;bean id=\"simplePointcut\" class=\"org.springframework.aop.support.NameMatchMethodPointcut\"&gt;\n\t\t&lt;property name=\"mappedName\" value=\"sayHello\" \/&gt;\n\t&lt;\/bean&gt;\n\t&lt;bean id=\"simpleAdvisor\" class=\"org.springframework.aop.support.DefaultPointcutAdvisor\"&gt;\n\t\t&lt;property name=\"pointcut\" ref=\"simplePointcut\" \/&gt;\n\t\t&lt;property name=\"advice\" ref=\"doAroundMethodBean\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"simpleServiceProxy\" class=\"org.springframework.aop.framework.ProxyFactoryBean\"&gt;\n\t\t&lt;property name=\"target\" ref=\"simpleServiceBean\" \/&gt;\n\t\t&lt;property name=\"interceptorNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;simpleAdvisor&lt;\/value&gt; \n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t&lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/pre>\n<p>We run the <code>App.class<\/code> again. Now, only the <code>sayHello(String message)<\/code> method is being intercepted.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code sty=\"\" le=\"color: black; word-wrap: normal;\">SimpleService : Method printNameId() : My name is Hello and my id is 12345\n--------------\nSimpleService: Method checkName() exception thrown..\n--------------\n****SPRING AOP**** DoAroundMethod: Method name : sayHello\n****SPRING AOP**** DoAroundMethod: Method arguments : [Javacodegeeks]\n****SPRING AOP**** DoAroundMethod: Before method executing!\nSimpleService : Method sayHello() : Hello! Javacodegeeks\n****SPRING AOP**** DoAroundMethod: After method executing!<\/code><\/pre>\n<p>Alternatively, you can use the <code>NameMatchMethodPointcutAdvisor<\/code>, to combine both pointcut and advisor bean definitions in one bean, as shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;highlight:[16,17,18,19]\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n&lt;bean id=\"doAroundMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoAroundMethod\" \/&gt;\n\t\n\t&lt;bean id=\"simpleAdvisor\" class=\"org.springframework.aop.support.NameMatchMethodPointcutAdvisor\"&gt;\n\t\t&lt;property name=\"mappedName\" value=\"sayHello\" \/&gt;\n\t\t&lt;property name=\"advice\" ref=\"doAroundMethodBean\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"simpleServiceProxy\" class=\"org.springframework.aop.framework.ProxyFactoryBean\"&gt;\n\t\t&lt;property name=\"target\" ref=\"simpleServiceBean\" \/&gt;\n\t\t&lt;property name=\"interceptorNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;simpleAdvisor&lt;\/value&gt; \n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t&lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/pre>\n<h3>4.2 regex match pointcut<\/h3>\n<p>Now, in order to create a pointcut that matches the method to be intercepted with a regular exression, we must define a new bean of <code>RegexpMethodPointcutAdvisor<\/code> type. The specific type of advisor has two properties. The <code>patterns<\/code> property holds a list of the patterns that are used for selecting the methods by their names that will be intercepted and applied the advice code. Here, in <code>regexAdvisor<\/code> we have used the <code>*Hello*<\/code> pattern, so again the <code>sayHello(String message)<\/code> method will be intercepted. The <code>advice<\/code> property holds a reference to the bean of the advice.[ulp id=&#8217;7POIYxRf1FUtPpmL&#8217;]<\/p>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;highlight:[16,17,18,19,20,21,22,23,24,30]\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n&lt;bean id=\"doAroundMethodBean\"\n\t\tclass=\"com.javacodegeeks.snippets.enterprise.aop.DoAroundMethod\" \/&gt;\n\n\t&lt;bean id=\"regexAdvisor\"\n\t\tclass=\"org.springframework.aop.support.RegexpMethodPointcutAdvisor\"&gt;\n\t\t&lt;property name=\"patterns\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;.*Hello.*&lt;\/value&gt;\n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t\t&lt;property name=\"advice\" ref=\"doAroundMethodBean\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"simpleServiceProxy\" class=\"org.springframework.aop.framework.ProxyFactoryBean\"&gt;\n\t\t&lt;property name=\"target\" ref=\"simpleServiceBean\" \/&gt;\n\t\t&lt;property name=\"interceptorNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;regexAdvisor&lt;\/value&gt;\n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t&lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/pre>\n<p>After running <code>App.java <\/code>class again we can see that only the method whose name matches the pattern <code>*Hello*<\/code> is being intercepted by the advice. The result is shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code sty=\"\" le=\"color: black; word-wrap: normal;\">SimpleService : Method printNameId() : My name is Hello and my id is 12345\n--------------\nSimpleService: Method checkName() exception thrown..\n--------------\n****SPRING AOP**** DoAroundMethod: Method name : sayHello\n****SPRING AOP**** DoAroundMethod: Method arguments : [Javacodegeeks]\n****SPRING AOP**** DoAroundMethod: Before method executing!\nSimpleService : Method sayHello() : Hello! Javacodegeeks\n****SPRING AOP**** DoAroundMethod: After method executing!<\/code><\/pre>\n<h2>5. AOP interceptors sequence<\/h2>\n<p>Now, let&#8217;s see how the sequence of the values in <code>interceptorNames<\/code> property of the proxy object can affect the sequence in which the advices intercept the methods. We create a new Around method advice, <code>DoAroundMethod2.java<\/code> class and add it to <code>applicationContext.xml<\/code> as shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>DoAroundMethod2.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.aop;\n\n\timport java.util.Arrays;\n\t \n\timport org.aopalliance.intercept.MethodInterceptor;\n\timport org.aopalliance.intercept.MethodInvocation;\n\npublic class DoAroundMethod2 implements MethodInterceptor {\n\t\tpublic Object invoke(MethodInvocation methodInvocation) throws Throwable {\n\t \n\t\t\tSystem.out.println(\"****SPRING AOP**** DoAroundMethod 2: Method name : \"\n\t\t\t\t\t+ methodInvocation.getMethod().getName());\n\t\t\tSystem.out.println(\"****SPRING AOP**** DoAroundMethod 2: Method arguments : \"\n\t\t\t\t\t+ Arrays.toString(methodInvocation.getArguments()));\n\t\t\t\/\/ same with MethodBeforeAdvice\n\t\t\tSystem.out.println(\"****SPRING AOP**** DoAroundMethod 2: Before method executing!\");\n\t \n\t\t\ttry {\n\t\t\t\t\/\/ proceed to original method call\n\t\t\t\tObject result = methodInvocation.proceed();\n\t\t\t\t\/\/ same with AfterReturningAdvice\n\t\t\t\tSystem.out.println(\"****SPRING AOP**** DoAroundMethod 2: After method executing!\");\n\t\t\t\treturn result;\n\t \n\t\t\t} catch (IllegalArgumentException e) {\n\t\t\t\t\/\/ same with ThrowsAdvice\n\t\t\t\tSystem.out.println(\"****SPRING AOP**** DoAroundMethod 2: When method throws Exception!\");\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n}<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;highlight:[15,22]\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"doAroundMethodBean\" class=\"com.javacodegeeks.snippets.enterprise.aop.DoAroundMethod\" \/&gt;\n\n\t&lt;bean id=\"doAroundMethod2Bean\" class=\"com.javacodegeeks.snippets.enterprise.aop.DoAroundMethod2\" \/&gt;\n\n\t&lt;bean id=\"simpleServiceProxy\" class=\"org.springframework.aop.framework.ProxyFactoryBean\"&gt;\n\t\t&lt;property name=\"target\" ref=\"simpleServiceBean\" \/&gt;\n\t\t&lt;property name=\"interceptorNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;doAroundMethodBean&lt;\/value&gt;\n\t\t\t\t&lt;value&gt;doAroundMethod2Bean&lt;\/value&gt;\n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t&lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/pre>\n<p>When running the application we can see that the around method advice whose bean is defined first in <code>simpleServiceProxy<\/code> is the one that intercepts the methods first.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code sty=\"\" le=\"color: black; word-wrap: normal;\">****SPRING AOP**** DoAroundMethod: Method name : printNameId\n****SPRING AOP**** DoAroundMethod: Method arguments : []\n****SPRING AOP**** DoAroundMethod: Before method executing!\n****SPRING AOP**** DoAroundMethod 2: Method name : printNameId\n****SPRING AOP**** DoAroundMethod 2: Method arguments : []\n****SPRING AOP**** DoAroundMethod 2: Before method executing!\nSimpleService : Method printNameId() : My name is Hello and my id is 12345\n****SPRING AOP**** DoAroundMethod 2: After method executing!\n****SPRING AOP**** DoAroundMethod: After method executing!\n--------------\n****SPRING AOP**** DoAroundMethod: Method name : checkName\n****SPRING AOP**** DoAroundMethod: Method arguments : []\n****SPRING AOP**** DoAroundMethod: Before method executing!\n****SPRING AOP**** DoAroundMethod 2: Method name : checkName\n****SPRING AOP**** DoAroundMethod 2: Method arguments : []\n****SPRING AOP**** DoAroundMethod 2: Before method executing!\n****SPRING AOP**** DoAroundMethod 2: When method throws Exception!\n****SPRING AOP**** DoAroundMethod: When method throws Exception!\nSimpleService: Method checkName() exception thrown..\n--------------\n****SPRING AOP**** DoAroundMethod: Method name : sayHello\n****SPRING AOP**** DoAroundMethod: Method arguments : [Javacodegeeks]\n****SPRING AOP**** DoAroundMethod: Before method executing!\n****SPRING AOP**** DoAroundMethod 2: Method name : sayHello\n****SPRING AOP**** DoAroundMethod 2: Method arguments : [Javacodegeeks]\n****SPRING AOP**** DoAroundMethod 2: Before method executing!\nSimpleService : Method sayHello() : Hello! Javacodegeeks\n****SPRING AOP**** DoAroundMethod 2: After method executing!\n****SPRING AOP**** DoAroundMethod: After method executing!<\/code><\/pre>\n<p>Now, let&#8217;s change the sequence of the interceptors in <code>simpleServiceProxy<\/code> bean and see what happens:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;highlight:[21,22]\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"doAroundMethodBean\" class=\"com.javacodegeeks.snippets.enterprise.aop.DoAroundMethod\" \/&gt;\n\n\t&lt;bean id=\"doAroundMethod2Bean\" class=\"com.javacodegeeks.snippets.enterprise.aop.DoAroundMethod2\" \/&gt;\n\n\t&lt;bean id=\"simpleServiceProxy\" class=\"org.springframework.aop.framework.ProxyFactoryBean\"&gt;\n\t\t&lt;property name=\"target\" ref=\"simpleServiceBean\" \/&gt;\n\t\t&lt;property name=\"interceptorNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;doAroundMethod2Bean&lt;\/value&gt;\n\t\t\t\t&lt;value&gt;doAroundMethodBean&lt;\/value&gt;\n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t&lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/pre>\n<p>Again, the first defined interceptor is the one that intercepts the methods first:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code sty=\"\" le=\"color: black; word-wrap: normal;\">****SPRING AOP**** DoAroundMethod 2: Method name : printNameId\n****SPRING AOP**** DoAroundMethod 2: Method arguments : []\n****SPRING AOP**** DoAroundMethod 2: Before method executing!\n****SPRING AOP**** DoAroundMethod: Method name : printNameId\n****SPRING AOP**** DoAroundMethod: Method arguments : []\n****SPRING AOP**** DoAroundMethod: Before method executing!\nSimpleService : Method printNameId() : My name is Hello and my id is 12345\n****SPRING AOP**** DoAroundMethod: After method executing!\n****SPRING AOP**** DoAroundMethod 2: After method executing!\n--------------\n****SPRING AOP**** DoAroundMethod 2: Method name : checkName\n****SPRING AOP**** DoAroundMethod 2: Method arguments : []\n****SPRING AOP**** DoAroundMethod 2: Before method executing!\n****SPRING AOP**** DoAroundMethod: Method name : checkName\n****SPRING AOP**** DoAroundMethod: Method arguments : []\n****SPRING AOP**** DoAroundMethod: Before method executing!\n****SPRING AOP**** DoAroundMethod: When method throws Exception!\n****SPRING AOP**** DoAroundMethod 2: When method throws Exception!\nSimpleService: Method checkName() exception thrown..\n--------------\n****SPRING AOP**** DoAroundMethod 2: Method name : sayHello\n****SPRING AOP**** DoAroundMethod 2: Method arguments : [Javacodegeeks]\n****SPRING AOP**** DoAroundMethod 2: Before method executing!\n****SPRING AOP**** DoAroundMethod: Method name : sayHello\n****SPRING AOP**** DoAroundMethod: Method arguments : [Javacodegeeks]\n****SPRING AOP**** DoAroundMethod: Before method executing!\nSimpleService : Method sayHello() : Hello! Javacodegeeks\n****SPRING AOP**** DoAroundMethod: After method executing!\n****SPRING AOP**** DoAroundMethod 2: After method executing!<\/code><\/pre>\n<h2>6. AOP auto proxy creators<\/h2>\n<p>An interesting feature of Spring is that it provides two auto proxy creators, so that we can create proxies for our beans automatically.<\/p>\n<h3>6.1 BeanNameAutoProxyCreator<\/h3>\n<p>The first auto proxy creator Spring provides is the <code>BeanNameAutoProxyCreator<\/code> that automatically creates AOP proxies for beans with names matching literal values or wildcards. In order to use it we must define it in <code>applicationContext.xml<\/code>. This creator exposes two properties for us to configure. The first property is <code>beanNames<\/code> and its value is a list of regular expressions matching the Spring bean names (ids) to be proxied. The second property is <code>interceptorNames<\/code> and its value is a list of the advisors (Spring bean ids) that will be used.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;highlight:[23,24,25,26,27,28,29,30,31,32,33,34]\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"doAroundMethodBean\" class=\"com.javacodegeeks.snippets.enterprise.aop.DoAroundMethod\" \/&gt;\n\n\t&lt;bean id=\"simplePointcut\" class=\"org.springframework.aop.support.NameMatchMethodPointcut\"&gt;\n\t\t&lt;property name=\"mappedName\" value=\"sayHello\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"simpleAdvisor\" class=\"org.springframework.aop.support.NameMatchMethodPointcutAdvisor\"&gt;\n\t\t&lt;property name=\"mappedName\" value=\"sayHello\" \/&gt;\n\t\t&lt;property name=\"advice\" ref=\"doAroundMethodBean\" \/&gt;\n\t&lt;\/bean&gt;\n\t&lt;bean class=\"org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator\"&gt;\n\t\t&lt;property name=\"beanNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;*ServiceBean&lt;\/value&gt;\n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t\t&lt;property name=\"interceptorNames\"&gt;\n\t\t\t&lt;list&gt;\n\t\t\t\t&lt;value&gt;simpleAdvisor&lt;\/value&gt;\n\t\t\t&lt;\/list&gt;\n\t\t&lt;\/property&gt;\n\t&lt;\/bean&gt;\n&lt;\/beans&gt;\n<\/pre>\n<p>Now we can load the <code>simpleServiceBean<\/code> in <code>App.java<\/code> class, without having to know if this bean has a proxy object or not. The <code>BeanNameAutoProxyCreator<\/code> will load the proxy.<br \/>\n<span style=\"text-decoration: underline;\"><em>App.java<\/em><\/span><\/p>\n<pre class=\"brush:java;highlight:[11]\">package com.javacodegeeks.snippets.enterprise;\n\nimport org.springframework.context.ConfigurableApplicationContext;\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\n\npublic class App {\n\n\tpublic static void main(String[] args) {\n\t\n\t\t\tConfigurableApplicationContext context = new ClassPathXmlApplicationContext(\"applicationContext.xml\");\n\t\t\tSimpleService simpleService = (SimpleService) context.getBean(\"simpleServiceBean\");\n\t\t\tsimpleService.printNameId();\n\t\t\tSystem.out.println(\"--------------\");\n\t\t\ttry{\n\t\t\t\tsimpleService.checkName();\n\t\t\t} catch(Exception e){\n\t\t\t\tSystem.out.println(\"SimpleService: Method checkName() exception thrown..\");\n\t\t\t}\n\t\t\tSystem.out.println(\"--------------\");\n\t\t\tsimpleService.sayHello(\"Javacodegeeks\");\n\t\t\tcontext.close();\n\t}\n}\n<\/pre>\n<p>The output is shown below:<br \/>\n<span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code sty=\"\" le=\"color: black; word-wrap: normal;\">SimpleService : Method printNameId() : My name is Hello and my id is 12345\n--------------\nSimpleService: Method checkName() exception thrown..\n--------------\n****SPRING AOP**** DoAroundMethod: Method name : sayHello\n****SPRING AOP**** DoAroundMethod: Method arguments : [Javacodegeeks]\n****SPRING AOP**** DoAroundMethod: Before method executing!\nSimpleService : Method sayHello() : Hello! Javacodegeeks\n****SPRING AOP**** DoAroundMethod: After method executing!<\/code><\/pre>\n<h3>6.2 DefaultAdvisorAutoProxyCreator<\/h3>\n<p>The second auto proxy creator Spring provides is the <code>DefaultAdvisorAutoProxyCreator<\/code> that automatically applies advisors in the current <code>applicationContext.xml<\/code>, without the need to include specific bean names in the auto-proxy advisor&#8217;s bean definition. In order to use it we must specify a <code>DefaultAdvisorAutoProxyCreator<\/code> bean definition in <code>applicationContext.xml<\/code>. Then we must specify any number of advisors in the same or related configuration files. The <code>DefaultAdvisorAutoProxyCreator<\/code> will automatically evaluate the pointcut contained in each advisor, to see what (if any) advice it should apply to each object.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>applicationContext.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;highlight:[25]\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:p=\"http:\/\/www.springframework.org\/schema\/p\"\n\txmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\n\txmlns:jee=\"http:\/\/www.springframework.org\/schema\/jee\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\"\n\txmlns:task=\"http:\/\/www.springframework.org\/schema\/task\"\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/aop http:\/\/www.springframework.org\/schema\/aop\/spring-aop-3.2.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.2.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.2.xsd http:\/\/www.springframework.org\/schema\/jee http:\/\/www.springframework.org\/schema\/jee\/spring-jee-3.2.xsd http:\/\/www.springframework.org\/schema\/tx http:\/\/www.springframework.org\/schema\/tx\/spring-tx-3.2.xsd http:\/\/www.springframework.org\/schema\/task http:\/\/www.springframework.org\/schema\/task\/spring-task-3.2.xsd\"&gt;\n\n\t&lt;bean id=\"simpleServiceBean\" class=\"com.javacodegeeks.snippets.enterprise.SimpleService\"&gt;\n\t\t&lt;property name=\"name\" value=\"Hello\" \/&gt;\n\t\t&lt;property name=\"id\" value=\"12345\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"doAroundMethodBean\" class=\"com.javacodegeeks.snippets.enterprise.aop.DoAroundMethod\" \/&gt;\n\n\n\t&lt;bean id=\"simplePointcut\" class=\"org.springframework.aop.support.NameMatchMethodPointcut\"&gt;\n\t\t&lt;property name=\"mappedName\" value=\"sayHello\" \/&gt;\n\t&lt;\/bean&gt;\n\n\t&lt;bean id=\"simpleAdvisor\" class=\"org.springframework.aop.support.NameMatchMethodPointcutAdvisor\"&gt;\n\t\t&lt;property name=\"mappedName\" value=\"sayHello\" \/&gt;\n\t\t&lt;property name=\"advice\" ref=\"doAroundMethodBean\" \/&gt;\n\t&lt;\/bean&gt;\n\t\n\t&lt;bean class=\"org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator\" \/&gt;\n\n&lt;\/beans&gt;\n<\/pre>\n<p>After running <code>App.java<\/code> class again the result is shown below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code sty=\"\" le=\"color: black; word-wrap: normal;\">SimpleService : Method printNameId() : My name is Hello and my id is 12345\n--------------\nSimpleService: Method checkName() exception thrown..\n--------------\n****SPRING AOP**** DoAroundMethod: Method name : sayHello\n****SPRING AOP**** DoAroundMethod: Method arguments : [Javacodegeeks]\n****SPRING AOP**** DoAroundMethod: Before method executing!\nSimpleService : Method sayHello() : Hello! Javacodegeeks\n****SPRING AOP**** DoAroundMethod: After method executing!<\/code><\/pre>\n<p>&nbsp;<br \/>\nThis was an example of Aspect Oriented Programming in Spring.<br \/>\nDownload the Eclipse project of this tutorial : <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/SpringAOPExample.zip\">SpringAOPExample.zip<\/a><a title=\"\" href=\"http:\/\/cdn.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/SpringAOPExample.zip\" target=\"_blank\" rel=\"external nofollow\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With this tutorial we shall show you how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide declarative enterprise services, especially as a replacement for EJB declarative services. It is also used to allow users to implement custom aspects, complementing their use of OOP with AOP. We &hellip;<\/p>\n","protected":false},"author":5,"featured_media":1248,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[465],"tags":[],"class_list":["post-5629","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring AOP Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"With this tutorial we shall show you how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring AOP Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"With this tutorial we shall show you how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-26T19:46:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-19T13:28:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Theodora Fragkouli\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Theodora Fragkouli\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"31 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/\"},\"author\":{\"name\":\"Theodora Fragkouli\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/2f9f5246a40f628c77a0b72499c1e697\"},\"headline\":\"Spring AOP Example\",\"datePublished\":\"2013-08-26T19:46:52+00:00\",\"dateModified\":\"2019-02-19T13:28:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/\"},\"wordCount\":1650,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"articleSection\":[\"AOP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/\",\"name\":\"Spring AOP Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"datePublished\":\"2013-08-26T19:46:52+00:00\",\"dateModified\":\"2019-02-19T13:28:35+00:00\",\"description\":\"With this tutorial we shall show you how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"spring\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"AOP\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/aop\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Spring AOP Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/2f9f5246a40f628c77a0b72499c1e697\",\"name\":\"Theodora Fragkouli\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Theodora-Fragkouli.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Theodora-Fragkouli.jpg\",\"caption\":\"Theodora Fragkouli\"},\"description\":\"Theodora has graduated from Computer Engineering and Informatics Department in the University of Patras. She also holds a Master degree in Economics from the National and Technical University of Athens. During her studies she has been involved with a large number of projects ranging from programming and software engineering to telecommunications, hardware design and analysis. She works as a junior Software Engineer in the telecommunications sector where she is mainly involved with projects based on Java and Big Data technologies.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\",\"https:\/\/gr.linkedin.com\/pub\/theodora-fragkouli\/66\/19\/983\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/theodora-fragkouli\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring AOP Example - Java Code Geeks","description":"With this tutorial we shall show you how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide","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:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/","og_locale":"en_US","og_type":"article","og_title":"Spring AOP Example - Java Code Geeks","og_description":"With this tutorial we shall show you how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-08-26T19:46:52+00:00","article_modified_time":"2019-02-19T13:28:35+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Theodora Fragkouli","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Theodora Fragkouli","Est. reading time":"31 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/"},"author":{"name":"Theodora Fragkouli","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/2f9f5246a40f628c77a0b72499c1e697"},"headline":"Spring AOP Example","datePublished":"2013-08-26T19:46:52+00:00","dateModified":"2019-02-19T13:28:35+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/"},"wordCount":1650,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","articleSection":["AOP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/","name":"Spring AOP Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","datePublished":"2013-08-26T19:46:52+00:00","dateModified":"2019-02-19T13:28:35+00:00","description":"With this tutorial we shall show you how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/aop\/spring-aop-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"spring","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/"},{"@type":"ListItem","position":5,"name":"AOP","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/aop\/"},{"@type":"ListItem","position":6,"name":"Spring AOP Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/2f9f5246a40f628c77a0b72499c1e697","name":"Theodora Fragkouli","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Theodora-Fragkouli.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Theodora-Fragkouli.jpg","caption":"Theodora Fragkouli"},"description":"Theodora has graduated from Computer Engineering and Informatics Department in the University of Patras. She also holds a Master degree in Economics from the National and Technical University of Athens. During her studies she has been involved with a large number of projects ranging from programming and software engineering to telecommunications, hardware design and analysis. She works as a junior Software Engineer in the telecommunications sector where she is mainly involved with projects based on Java and Big Data technologies.","sameAs":["http:\/\/www.javacodegeeks.com\/","https:\/\/gr.linkedin.com\/pub\/theodora-fragkouli\/66\/19\/983"],"url":"https:\/\/examples.javacodegeeks.com\/author\/theodora-fragkouli\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/5629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=5629"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/5629\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1248"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=5629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=5629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=5629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}