Warning: include(../include/breadcrumb.php): Failed to open stream: No such file or directory in /home/javabykiran/public_html/thekiranacademy.com/tutorials/configure-project-for-spring-aop-with-java-configuration-annotations.php on line 16

Warning: include(): Failed opening '../include/breadcrumb.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/javabykiran/public_html/thekiranacademy.com/tutorials/configure-project-for-spring-aop-with-java-configuration-annotations.php on line 16

Warning: include(./spring-aop-sidenav.php): Failed to open stream: No such file or directory in /home/javabykiran/public_html/thekiranacademy.com/tutorials/configure-project-for-spring-aop-with-java-configuration-annotations.php on line 21

Warning: include(): Failed opening './spring-aop-sidenav.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/javabykiran/public_html/thekiranacademy.com/tutorials/configure-project-for-spring-aop-with-java-configuration-annotations.php on line 21

Configure project for AOP with java Configuration-annotations

Step 1: Add maven dependency. pom.xml should look like this.


Step 2: write any class (Joint Point)


Step 3: write code for AspectJ class

  • In below code pointcut expression is
    [@Before ("execution (* com.javabykiran.Invoice.*())")]

  • Meaning of this is call this before Advice before to all methods/joint points inside Invoice class.

  • Spring AOP users are likely to use the execution pointcut designator the most often. The format of an execution expression is:

    execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern) throws-pattern?)

    The parameters pattern is slightly more complex: () matches a method that takes no parameters, whereas (..) matches any number of parameters (zero or more).

    Example may be like this
    [@Before ("execution (* com.javabykiran.Invoice.payCash(*,String))")]

  • The pattern (*) matches a method taking one parameter of any type, (*, String) matches a method taking two parameters, the first can be of any type, the second must be a String.

  • This class is aspect

  • This class have pointcut expressions mentioned on advice

  • These advices will perform action on jointpoints if pointcut expression satisfies.

  • execution - for matching method execution join points, this is the primary pointcut designator you will use when working with Spring AOP

  • * - modifier-pattern

  • com.javabykiran.Invoice - Full package name with class name

  • * means all methods of invoice class

  • Different patterns will be explained at the end of this chapter


Step 4: write config class for configuration

  • @EnableAspectJAutoProxy to enable aop

  • @bean must include AspectJ class as well- AspectCode bean


Step 5: Client code


Step 6: See output



Warning: include(../include/google-vertical-ads.php): Failed to open stream: No such file or directory in /home/javabykiran/public_html/thekiranacademy.com/tutorials/configure-project-for-spring-aop-with-java-configuration-annotations.php on line 233

Warning: include(): Failed opening '../include/google-vertical-ads.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/javabykiran/public_html/thekiranacademy.com/tutorials/configure-project-for-spring-aop-with-java-configuration-annotations.php on line 233

Warning: include(../include/internal-page-footer.php): Failed to open stream: No such file or directory in /home/javabykiran/public_html/thekiranacademy.com/tutorials/configure-project-for-spring-aop-with-java-configuration-annotations.php on line 273

Warning: include(): Failed opening '../include/internal-page-footer.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/javabykiran/public_html/thekiranacademy.com/tutorials/configure-project-for-spring-aop-with-java-configuration-annotations.php on line 273