Mach-II Environment Properties and ColdSpring Bean Reference

50 views
Skip to first unread message

Will Yu

unread,
Apr 23, 2012, 2:49:55 PM4/23/12
to Mach-II for CFML
Hello,

I'm definitely very new to Mach-II and I'm experiencing some
difficulties on how to pull the proper ${dsn} variable from a Multiple
Environment settings in my config file. My development, testing and
production all have different DSN variable names/values. It looks
like my config file is setup properly because my application starts up
and runs with no problem, but only when I define <property name="dsn"
value="datasource_name" />. The coldspring.xml references the <value>$
{dsn}</value> and is able to pull this info.

BUT I want to delete that <property> tag and use the "Environment
Settings" listed below:

<property name="environment"
type="MachII.properties.EnvironmentProperty">
<parameter name="dev-main>
<struct>
<key name="properties">
<struct>
<key name="dsn" value="datasource1" />
</struct>
</key>
</struct>
</parameter>
<parameter name="test-main>
<struct>
<key name="properties">
<struct>
<key name="dsn" value="datasource2" />
</struct>
</key>
</struct>
<parameter name="production-main>
<struct>
<key name="properties">
<struct>
<key name="dsn" value="datasource2" />
</struct>
</key>
</struct>
</parameter>
</parameter>
</property>

What variable do I put in my coldspring.xml file so it knows which
datasource to pull from depending on the environment it is in? ${dsn}
does not work within this file but when I do getProperty("dsn") it
pulls the correct dsn value?

Thanks,
Will

jason.york

unread,
Apr 24, 2012, 9:40:35 AM4/24/12
to mach-ii-for...@googlegroups.com
Hi Will,

One thing I noticed is that you're missing end quotes after your environment names.. eg "dev-main

Also you may want to consider using the default environments (local, test, qa, stage, prod) I think those names have special meaning to Mach-ii.

You're also missing the <parameters> tag.  So If I were to rewrite your code, it would look something like:

<property name="environment" type="MachII.properties.EnvironmentProperty">
    <parameters>
        <parameter name="defaultEnvironmentName" value="local" />

        <parameter name="local">

            <struct>
                <key name="properties">
                    <struct>
                        <key name="dsn" value="datasource1" />
                    </struct>
                </key>
            </struct>
        </parameter>
        <parameter name="test">
            <struct>
                <key name="properties">
                    <struct>
                        <key name="dsn" value="datasource2" />
                    </struct>
                </key>
            </struct>
        </parameter>       
        <parameter name="prod">

            <struct>
                <key name="properties">
                    <struct>
                        <key name="dsn" value="datasource2" />
                    </struct>
                </key>
            </struct>
        </parameter>       
    </parameters>
</property>


Hope that helps!

-- Jason

Brian Klaas

unread,
Apr 24, 2012, 9:44:30 AM4/24/12
to mach-ii-for...@googlegroups.com
Hi Will -

It looks like you're missing the <servers> key from your Environment config file. This is what Mach-II uses to match a server to an environment. Your dev node, for example, would need to look like:

<parameter name="dev-main>
   <key name="servers" value="localhost" />

    <struct> 
      <key name="properties"> 
        <struct> 
          <key name="dsn" value="datasource1" /> 
        </struct> 
      </key> 
    </struct> 
  </parameter> 

You should also have an <environmentGroup> key in there as well:

<key name="environmentGroup" value="local" />

If you _do_ have that in your config but omitted it from your post, then make sure you're using the ColdSpring property CFC and not the deprecated ColdSpring plugin. Environment config variables and ColdSpring will only work with the CS property CFC.

brian

William Yu

unread,
Apr 24, 2012, 10:13:05 AM4/24/12
to mach-ii-for...@googlegroups.com
Jason,

Thanks for the suggestion I'll definitely give it a try.  Just to be clear I do have all the nodes you've given as an example as well as the nodes mentioned by Brian.  I just didn't include it in my entry.  To be clear my I believe I understand the config file well enough to have my application running, BUT with the exception to my coldspring.xml file.

As you know I have all these environments for my project but I don't want to be in the business of having a different mach-ii.xml file different on each of my environment because I'm defining <property name="dsn" value="some_datasource" /> just so my coldspring.xml file can pick up the <value>${dsn}</value> parameter.  I don't believe that makes my code portable.  My goal is to be able to put this code on any server and with no changes, because the logic is there already to determine the environments.

So the question what's the <value>${????}</value> do I need to be placed into my coldspring.xml file so it will dynamically pick up the proper dsn from my environment nodes?  I know the framework itself knows the proper dsn, because when I do a getProperty("dsn") call it pulls the correct information but I can't seem to find the correct variable for my coldspring.xml file.

Thanks in advance for all that have already replied and I would greatly appreciate any more clarification.

Will 

--
To post to this group, send email to mach-ii-for...@googlegroups.com
For more options and to unsubscribe, visit this group at http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
 
SVN: http://svn.mach-ii.com/machii/
Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/

Brian Klaas

unread,
Apr 25, 2012, 9:12:37 AM4/25/12
to mach-ii-for...@googlegroups.com
Will - are you using ColdSpring 2.0 by any chance? I'm not sure if the Mach-II ColdSpring property works with CS 2.0 just yet. Jason, Peter or Kurt might know if the current CS property is compatible with CS 2.0.

I do know that if you have all the nodes in your environment config XML file, set the dsn value in your environment config file, and you're using the ColdSpring property, it does work. It's used in all of our production apps.

brian
--
To post to this group, send email to mach-ii-for-coldfusion@googlegroups.com

William Yu

unread,
Apr 25, 2012, 9:31:43 AM4/25/12
to mach-ii-for...@googlegroups.com
Brian,

I'm not sure but based from the frameworkProperties.properties file it say the "majorVersion=1.2"  So assume it's not 2.0 but I could be wrong.

So are you saying that the <value>${dsn}</value> "should" automatically pick up my dsn value from my config file, if I'm not using CS 2.0?  I do apologize I'm dragging this thread on and on I figured it would be a simple solution to this matter and I was missing something on my end.

Thanks,
Will

--
To post to this group, send email to mach-ii-for...@googlegroups.com

Joel Cox

unread,
Apr 25, 2012, 1:06:22 PM4/25/12
to Mach-II for CFML
I've gotten nothing but errors attempting to bring up the ColdSpring
website in the last week. Anyone know what's going on? Is CS dead?

Brian Klaas

unread,
Apr 30, 2012, 8:23:56 AM4/30/12
to mach-ii-for...@googlegroups.com
Hi Will -

It should automatically pick up the correct ${dsn} value from your config file, and it sounds like you're using CS 1.2.

The only other thing I can possibly think of is the hyphen in your environment names. I really doubt this is it, but if the environment names are somehow being evaluated along the way, CF could be trying to evaluate two variables rather than treating it as a string. I really doubt this is it, but you could try that.

Also - have you checked to make sure that any other properties in your environment config are being propagated down into the rest of your Mach-II app? It could be an issue with environmentConfig as a whole, and not just CS. Probably worthwhile to eliminate any other possible problems.

brian
Reply all
Reply to author
Forward
0 new messages