Posted in ColdFusion | Posted on 09-23-2009 | 4,076 views
While I've used Model-Glue for many years now, I've only recently begun to seriously drink the ColdSpring kool-aid. The more I use ColdSpring, the more I appreciate how well it works with Model-Glue. I'm writing up some recommendations for Model-Glue application design, and one of the things that occurred to me is that while I typically recommend breaking up the ModelGlue.xml file into multiple files, it might also make sense to break up the ColdSpring.xml file. Right now this file contains the settings for your Model-Glue application (reload, debug, etc) and any custom beans you want defined.
So I spoke with Scott Stroz about this and he clued me in to the fact that this is actually already possible! So big thanks to him for teaching me this tip, and hopefully it will help others as well.
To begin, create your custom beans.xml file. I'd keep it in config with the rest of the config files. Remember, this is the file that will store all the beans for your application. Your ColdSpring.xml file will only be used to configure the Model-Glue settings for the application.
Next, you create a new instance of ColdSpring and store it within the Application scope. I modified the Model-Glue default Application.cfc like so:
2 <cfset application.cs = createObject("component", "coldspring.beans.DefaultXmlBeanFactory").init()>
3 <cfset application.cs.loadBeansFromXmlFile("/mgtest/config/beans.xml", true)>
4</cffunction>
Ok, one last step. When it comes to working with ColdSpring, there is a setting you can override in the main index.cfm file:
2 **HIERARCHIAL BEAN FACTORY SUPPORT**
3
4 If you'd like to designate a parent bean factory for the one that powers Model-Glue,
5 simply do whatever you need to do to set the following value to the parent bean factory
6 instance:
7
8 <cfset ModelGlue_PARENT_BEAN_FACTORY = ??? />
9--->
I never really paid attention to this before, but this is what we need to change. Simply add:
And bam - you're done. My biggest concern was that this wouldn't be as "tied" as when you just use ColdSpring.xml. However, that proved to be completely incorrect. I was able to define beans within my controller just fine:
And then use it within a controller mehtod:
Woot. Thanks Scott, thanks Model-Glue, and thanks ColdSpring.


This is great, but why not just break them up this way right inside your coldspring.xml file?
<!-- IMPORT COMMON BEANS -->
<import resource="/SymphonyCore/config/beans/ReactorFactory.xml" />
<import resource="/SymphonyCore/config/beans/CommonBeans.xml" />
I have done this for a long time and it is a lot easier than the method you mentioned.
Am I wrong?
Josh
a) This isn't mentioned in the reference guide at all. :( I need to bug Chris Scott on it.
b) I'd still probably prefer a separate set of files for this. So while I can see using the IMPORT directive, I'd do it from my custom beans.xml file, just to keep things segregated between my services and my MG settings. But that's just my opinion.
Thanks for all of your helpful blog posts.
Josh
Is that correct?
You do bring up a good side point though. If I edit my beans.xml, I'd have to ensure I rerun onApplicationStart(). I'd just add a hook to onRequestStart that does that, and uses the same URLs hooks as ModelGlue.
But my guess would be that the <import> technique mentioned by Josh WOULD do a re-instantiate the imported bean factories. Can you confirm that Josh?
- JS
@Josh: I do it the same way and never ever noticed any problems with it. So I'm very happy with it.
Hope, my points aren't lost in translation...
[Add Comment] [Subscribe to Comments]