smruti ranjan smruti ranjan - 9 months ago 47
Java Question

@Aspectj based AOP : Advice is not getting called

Read the related queries here, but none of them were help ful.

This is my xml file :

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=""
xsi:schemaLocation=" ">

<bean id="advice1" class="Aspects.Advice"></bean>

<bean id="module1" class="objects.Modules">
<constructor-arg index="0"> <ref bean="resource1"/> </constructor-arg>
<constructor-arg index="1" value="10 Oct"></constructor-arg>
<constructor-arg index="2" value="11 Oct"></constructor-arg>

<property name="moduleName" value="SaleLayaway"></property>
<bean id="resource1" class="objects.Resource">
<property name="name" value="Smruti"></property>
<property name="designation" value="PA"></property>
<property name="teamName" value="BackEnd"></property>

This is my Aspect :

package Aspects;

public class Advice {

@Pointcut("execution(public void Modules.displayModule*.*(..))")
public void pointCut1()//point cut name


public void inputLogger(JoinPoint jp)
System.out.println(" inside advice");
System.out.println("We are gonna start service signature :"+jp.getSignature());
System.out.println("Target name: "+jp.getTarget());


This is my main "Modules" having "displayModuleInfo" method where I need to add the advice:

package objects;

public class Modules {

private Resource rescource;
private String startDate;
private String finsihDate;
private String moduleName;

public String getModuleName() {
return moduleName;

public void setModuleName(String moduleName) {
this.moduleName = moduleName;

public Modules(Resource rescource, String startDate, String finsihDate) {
this.rescource = rescource;
this.startDate = startDate;
this.finsihDate = finsihDate;

public Modules(){

public Modules(Resource rescource) {
this.rescource = rescource;

public void displayModuleInfo(){
System.out.println(" module name: "+moduleName);
System.out.println(" Resource name : "+rescource.getName()+":Designation :"+rescource.getDesignation()+" : team name :"+rescource.getTeamName());
System.out.println(" module start date :"+startDate+" : finish date : "+finsihDate);


I am not able to identify why advices are not working. This is the o/p i am getting

log4j:WARN No appenders could be found for logger (
log4j:WARN Please initialize the log4j system properly.
module name: SaleLayaway
Resource name : Smruti:Designation :PA : team name :BackEnd
module start date :10 Oct : finish date : 11 Oct

I have these added these jars for AOP:
enter image description here

Whats the obvious thing I am missing here ?

Answer Source

Your pointcut declaration seems to be malformed. I created a sample app and it seems that it should be :

@Pointcut("execution(public void objects.Modules.displayModule*(..))")
public void pointCut1()//point cut name


This declaration matches any method, where name starts with displayModule declared by the objects.Modules class. IIRC your declaration would match any method, declared by a class which name starts with displayModule residing in the Modules package.

In case you missed it, the reference has great examples on how to create pointcuts.