|
From: Christophe V. <c.v...@pa...> - 2004-01-20 21:08:49
|
Hello,
I'm using MethodInvokingFactoryBean to retrieve an instance of an class using
another instance of another class. If I implement InitializingBean, the
afterPropertiesSet method never gets called.
But that is not only the case with InitializingBean, it shows the same
behaviour when implementing ApplicationListenener, OnApplicationEvent never
seems to get called.
Is this normal behaviour?
I checked the bug system for something on MethodInvokingFactoryBean, but I
couldn't find anything. Should I file a bug about this?
If this is normal behavior, what is the correct way to achieve what I need (an
object instantiated outside of the beanfactory, but that still will be able
to implement Spring specific interfaces and expect them to work.
Here is a small test setup:
---test/testThingy.xml---
<beans>
<bean id="thingyCreator" class="test.ThingyCreator" singleton="true"/>
<bean id="thingy"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="target"><ref local="thingyCreator"/></property>
<property name="targetMethod"><value>getThingy</value></property>
</bean>
<bean id="otherThingy" class="test.OtherThingy" />
</beans>
---test.ThingyCreator----
package test;
public class ThingyCreator {
private Thingy thingy = new Thingy();
public Thingy getThingy() {
return this.thingy;
}
}
---test.Thingy---
package test;
public class Thingy implements
org.springframework.beans.factory.InitializingBean {
public Thingy() {
System.err.println("thingy constructor");
}
public void afterPropertiesSet() throws Exception {
System.err.println("Thingy: I never get called");
}
}
---test.OtherThingy---
package test;
public class OtherThingy implements
org.springframework.beans.factory.InitializingBean {
public OtherThingy() {
System.err.println("OtherThingy constructor");
}
public void afterPropertiesSet() throws Exception {
System.err.println("OtherThingy: I get called");
}
}
---test.Main---
package test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) throws Exception {
ApplicationContext context = new
ClassPathXmlApplicationContext("/test/testThingy.xml");
//prints "I get called"
OtherThingy ot = (OtherThingy)context.getBean("otherThingy");
//doens't print anything, but I think it should
Thingy t = (Thingy)context.getBean("thingy");
}
}
--
Kind regards,
Christophe Vanfleteren
|