Jeff,
I'm glad we could help you. However, I also forgot a last thing that I'm not sure
you were aware. For your MyBeforeAdvice to work on multiple target instances, your
advice/advisor must be a prototype, otherwise the same advice instance will be used
for each target, thus only on one of your targets would init be called.
Vickyk,

Originally Posted by
vickyk
I am sure about the RegexpMethodPointcutAdvisor , I have not been aware of regular expression as the word . Do you mean the following snippet
[...]
can be replaced by
[...]
No, what I meant is replacing the XML code:
Code:
<bean id="beforeAdvice" class="MyBeforeAdvice"/>
<bean id="beforeAdvisor"
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice"><ref local="beforeAdvice"/></property>
<property name="pattern"><value>.*</value></property>
</bean>
<bean id="test1" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces"><value>TestBean</value></property>
<property name="target"><bean class="TestBeanImpl"/></property>
<property name="interceptorNames">
<list>
<value>beforeAdvisor</value>
</list>
</property>
</bean>
by
Code:
<bean id="beforeAdvice" class="MyBeforeAdvice"/>
<bean id="test1" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces"><value>TestBean</value></property>
<property name="target"><bean class="TestBeanImpl"/></property>
<property name="interceptorNames">
<list>
<value>beforeAdvice</value>
</list>
</property>
</bean>
And previously, for the Advice/Advisor thing, I meant that instead of the
MyAdvisor defined in Jeff's post, he could use the following code, with the
new XML snippet I mentionned above. But I considering the name change from
MyBeforeAdvice in the first post, to MyAdvisor in the second, I guess it's
what he did at first, except with the XML snippet using the RegexpMethodPointcutAdvisor.
Code:
public class MyBeforeAdvice implements MethodBeforeAdvice {
private boolean initialised = false;
public synchronized void before(Method method, Object[] args, Object target) throws Throwable {
if (!initialised && target instanceof Initializable) {
Initializable i = (Initializable)o;
i.init();
initialised = true;
}
}
}

Originally Posted by
vickyk
Should not the Introduciton Advisor be used in the case of matching all the methods ?
The purpose of the Introduction Advisor is to add interfaces to a target, it isn't for interception of existing methods.