ColdSpring DI with onMissingMethod
I've had the chance to play around with ColdSpring today. One of the things I wanted to know was if you could use it with onMissingMethod to pass in dependancies.
In ColdSpring you can either choose to have all the dependency injection handled for you auto-magically (using the default-autowire="byName"' attribute of the beans node) or define them yourself, or even a combination of the two!
Here's a quick snippet of our config when using autowire if MyObject has a dependency on SomeObject:
<bean id="SomeObject" class="mypath.SomeObject" />
<bean id="MyObject" class="mypath.MyObject" />
ColdString figures out that there is a method called setSomeObject in MyObject and automatically passes SomeObject to it. Clever stuff.
Here's a quick snippet of explicitly passing the dependency without using autowire:
<bean id="SomeObject" class="mypath.SomeObject" />
<bean id="MyObject" class="mypath.MyObject">
<!-- set the dependancy -->
<property name="SomeObject">
<ref bean="SomeObject" />
</property>
</bean>
The autowire will only work if you have a method called setSomeObject. However when you explicitly pass the dependency you can use onMissingMethod without having to actually create a setSomeObject method.
Personally I prefer to have a concrete API and tend not to use onMissingMethod, but it is interesting to know that you can do it. It could be quite useful for rapid prototyping (although you loose the ability to use autowire).
- Posted in:
- ColdFusion
- Coldspring


However, it's very interesting to know that explicit dependencies allow the use of onMissingMethod() - I hadn't tried that and I'm a big fan of oMM :)
Comment by Sean Corfield – March 06, 2009
I seem to remember someone doing a presentation on onMissingMethod at SOTR 08... :)
Comment by John Whish – March 06, 2009