Hi all,
I am trying to use the auto proxying feature of Spring AOP. There are two ways to do it
1. using the basic auto proxying
2. using @AspectJ Annotation.
I tried running sample code for both, and could not see the auto prozying feature for both. But I am concentrating only on the way 2.
Here are the relevant code fragments:
The XML, the AOP part of it:
The
Java Classes:
I am using a plain java application that gets bean and uses them as:
The code for the Performer Interface:
package com.springinaction.springidol;
When I run the application, I get to see only tthe sys outs of the Instrumentalist class and the Saxophone class. This shows that the functionality of the aspect is not associated with the bean. Am I missing something?
The code for Instrumentalist class
package com.springinaction.springidol;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
public class Instrumentalist implements Performer, InitializingBean, DisposableBean {
private String song;
private Instrument instrument;
private Stage stage;
public Instrumentalist() {}
public void perform() throws Exception {//PerformanceException
System.out.print("Playing " + song + " : ");
instrument.play();
}
public void setSong(String song) {
this.song = song;
}
public void setInstrument(Instrument instrument) {
this.instrument = instrument;
}
public Stage getStage() {
return stage;
}
public void setStage(Stage stage) {
this.stage = stage;
}
public void tuneInstrument() {
instrument.tune();
}
public void cleanInstrument() {
instrument.clean();
}
public void afterPropertiesSet() throws Exception {
instrument.tune();
}
public void destroy() throws Exception {
instrument.clean();
}
}