<p>In this article, we will explore Spring AOP XML configuration. How to use pure XML configuration without any annotations. I have used aop namespaces.</p>
<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<p>We&#8217;ll learn how to configure aspects, advice and pointcuts using the traditional XML way.</p>
<pre class="highlight">package com.dineshonjava.Spring.Aop; 
 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
 
import com.venkat.Spring.Aop.service.ShapeService; 
 
public class AopTest { 
public static void main(String args[]) 
{ 
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml"); 
ShapeService service=context.getBean("shapeService",ShapeService.class); 
service.getCircle(); 
} 
} 
</pre>
<div id="ads-id" align="center"></div>
<div style="background-color: #f2f9fc; border:1px solid #c9e6f2;border-radius:3px;padding:16px;line-height:1.45;">
<span style="color: red;font-size: x-large;text-align: center;"><b>Popular Tutorials</b></span></p>
<ul style="text-align: left;">
<li><b><a href="https://dineshonjava.com/spring-tutorial/"><em><strong>Spring Tutorial</strong> </em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><strong><em>Spring MVC Web Tutorial </em></strong></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-spring-boot-a-spring-boot-complete-guide/"><strong>Spring Boot Tutorial</strong> </a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-take-baby-step-to-secure/"><em>Spring Security Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-tutorial-with-example-aspect-advice-pointcut-joinpoint/"><em>Spring AOP Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/using-spring-jdbc-framework-chapter-32/"><em>Spring JDBC Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-hateoas-hypermedia-driven-restful-web-service/"><em><strong>Spring HATEOAS </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/microservices-with-spring-boot/"><em><strong>Microservices with Spring Boot</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/jax-rs-web-service-tutorial/"><strong><em>REST Webservice</em> </strong></a></b></li>
<li><b><a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/"><em><strong>Core Java </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/hibernate-3-on-baby-steps/"><em><strong>Hibernate Tutorial</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-batch-process-with-example/"><strong><em>Spring Batch</em> </strong></a></b></li>
</ul>
</div>
<pre class="highlight">package com.dineshonjava.Spring.Aop; 
 
public @interface Loggable { 
 
} 
</pre>
<pre class="highlight">package com.dineshonjava.Spring.Aop; 
 
import org.aspectj.lang.ProceedingJoinPoint; 
import org.aspectj.lang.annotation.Aspect; 
 
@Aspect 
public class LoggingAspect { 
 
// @Pointcut("execution(* get*())") 
// public void allGetters(){} 
// @Around("@annotation(com.dineshonjava.Spring.Aop.Aspect.Loggable)") 
public Object myAroundAdvice(ProceedingJoinPoint proceedingJoinPoint) 
{ 
Object returnValue=null; 
try { 
System.out.println("Before method Executed"); 
returnValue=proceedingJoinPoint.proceed(); 
System.out.println("After Method Executed...."); 
} catch (Throwable e) { 
System.out.println("Around Advice throws exception"); 
} 
System.out.println("After Finally executed........"); 
return returnValue; 
} 
} 
</pre>
<pre class="highlight">package com.dineshonjava.Spring.Aop; 
 
 public class Circle { 
 
private String name; 
 
public String getName() { 
return name; 
} 
 
public void setName(String name) { 
this.name = name; 
System.out.println("Setter method is called....."); 
throw(new RuntimeException()); 
} 
public String setNameAndReturning(String name) { 
this.name = name; 
System.out.println("Setter Method and return the value method executed...."); 
return name; 
} 
} 
</pre>
<pre class="highlight">package com.dineshonjava.Spring.Aop; 
 
 public class Triangle { 
 
private String name; 
 
public String getName() { 
return name; 
} 
 
public void setName(String name) { 
this.name = name; 
} 
} 
</pre>
<pre class="highlight">package com.dineshonjava.Spring.Aop; 
 
import com.dineshonjava.Spring.Aop.Aspect.Loggable; 
import com.dineshonjava.Spring.Aop.model.Circle; 
import com.dineshonjava.Spring.Aop.model.Triangle; 
 
public class ShapeService { 
 
private Triangle triangle; 
private Circle circle; 
public Triangle getTriangle() { 
return triangle; 
} 
public void setTriangle(Triangle triangle) { 
this.triangle = triangle; 
} 
@Loggable 
public Circle getCircle() { 
return circle; 
} 
public void setCircle(Circle circle) { 
this.circle = circle; 
} 
} 
</pre>
<p> ;</p>
<pre class="highlight"><;beans xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">; 
<;aop:aspectj-autoproxy>; 
<;bean class="com.dineshonjava.Spring.Aop.model.Triangle" name="triangle">; 
<;property name="name" value="triangle name">; 
<;/property>;<;/bean>; 
<;bean class="com.dineshonjava.Spring.Aop.model.Circle" name="circle">; 
<;!-- <;property name="name" value="circle name"/>; -->; 
<;/bean>; 
<;bean class="com.dineshonjava.Spring.Aop.service.ShapeService" name="shapeService">; 
<;property name="triangle" ref="triangle">; 
<;property name="circle" ref="circle">; 
<;/property>;<;/property>;<;/bean>; 
<;bean class="com.dineshonjava.Spring.Aop.Aspect.LoggingAspect" name="loggingAdviceBean">; 
<;aop:config>; 
<;aop:aspect id="loggingAdvice" ref="loggingAdviceBean">; 
<;aop:pointcut expression="execution(* get*())" id="allGetters">; 
<;aop:around method="myAroundAdvice" pointcut-ref="allGetters">; 
<;/aop:around>;<;/aop:pointcut>;<;/aop:aspect>; 
<;/aop:config>; 
<;/bean>;<;/aop:aspectj-autoproxy>;<;/beans>; 
</pre>
<p> ;</p>
<div style="background-color: #f2f9fc; border-radius: 3px; border: 1px solid #c9e6f2; line-height: 1.45; padding: 16px;">
<span style="color: red; font-size: x-large; text-align: center;"><b>Spring AOP Related Posts</b></span></p>
<ol style="text-align: left;"><span style="color: #274e13;"></p>
<li><b><a href="https://dineshonjava.com/spring-aop-interview-questions-and-answers/"><span style="color: red;">Spring AOP Interview Questions and Answers</span></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-aop-in-spring/"><span style="color: red;">Spring AOP-Introduction to Aspect Oriented Programming</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aspect-annotation/"><span style="color: red;">@Aspect Annotation in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/after-advice-type-and-around-advice/"><span style="color: red;">Advices in Spring AOP </span></a></b></li>
<li><b><a href="https://dineshonjava.com/joinpoints-and-advice-arguments-chapter/"><span style="color: red;">Spring AOP JoinPoints and Advice Arguments</span></a></b></li>
<li><b><a href="https://dineshonjava.com/pointcuts-and-wildcard-expressions/"><span style="color: red;">Spring AOP-Declaring pointcut Expressions with Examples</span></a></b></li>
<li><b><a href="https://dineshonjava.com/aop-xml-configuration-chapter-30/"><span style="color: red;">Spring AOP XML configuration</span></a></b></li>
<li><b><a href="https://dineshonjava.com/xml-schema-based-aop-example/"><span style="color: red;"> Spring AOP XML Schema based Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-aspectj-before-annotation-advice-example/"><span style="color: red;"> Spring AOP AspectJ @Before Annotation Advice Example<br />
</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-before-advice-example-using-xml-config/"><span style="color: red;"> Spring AOP Before Advice Example using XML Config</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-aspectj-after-annotation-advice-example/"><span style="color: red;"> Spring AOP AspectJ @After Annotation Advice Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-after-advice-example-using-xml-config/"><span style="color: red;"> Spring AOP After Advice Example using XML Config</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-aspectj-after-returning-annotation-advice-example/"><span style="color: red;"> Spring AOP AspectJ @AfterReturning Annotation Advice Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-after-returning-advice-example-using-xml-config/"><span style="color: red;"> Spring AOP After-Returning Advice Example using XML Config</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-aspectj-after-throwing-annotation-advice-example/"><span style="color: red;"> Spring AOP AspectJ @AfterThrowing Annotation Advice Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-after-throwing-advice-example-using-xml-config/"><span style="color: red;"> Spring AOP After Throwing Advice Example using XML Config</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-aspectj-around-annotation-advice-example/"><span style="color: red;"> Spring AOP AspectJ @Around Annotation Advice Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-around-advice-example-using-xml-config/"><span style="color: red;"> Spring AOP Around Advice Example using XML Config</span></a></b></li>
<li><b><a href="https://dineshonjava.com/writing-first-aspectj-program-in-spring/"><span style="color: red;">Spring AOP Writing First AspectJ Program in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/understanding-aop-proxies-chapter-31/"><span style="color: red;">Spring AOP Proxies in Spring</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-transaction-management-in/"><span style="color: red;"> Spring AOP Transaction Management in Hibernate</span></a></b></li>
<li><b><a href="https://dineshonjava.com/transaction-management-in-spring/"><span style="color: red;">Spring Transaction Management</span></a></b></li>
<li><b><a href="https://dineshonjava.com/declarative-transaction-management/"><span style="color: red;">Spring Declarative Transaction Management Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-ordering-of-aspects-with-example/"><span style="color: red;">Spring AOP-Ordering of Aspects with Example</span></a></b></li>
<p></span></ol>
</div>
<p> ;</p>
</div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/after-advice-type-and-around-advice/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/understanding-aop-proxies-chapter-31/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '639'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…