I spent the better part of my day trying to solve an issue where I construct a named configuration property, then I wanted to get that property from the config object.

Seemed simple enough… NOT FOR ME. Maybe it was just a Friday or something but…. Here is what I found

I was able to assert the correct values in many different ways except the one I needed

        def config = ConfigurationHolder.config
        String srcProperty = "${tagBundleName}.audio" + ((locale)? "_${locale}" : '')

        assert srcProperty == "prompt.welcomeMessageOverrideGreeting.audio"
        assert "${config.prompt.welcomeMessageOverrideGreeting.audio}" == "/en/someFileName.wav"

I must have spent 4 hours on this and never found any answer until I ran across the closest thing to what I needed:


And this worked for trying to eval that property:

assert Eval.me( "config", config, "config.${txtProperty}" ) == "Text alternative for /en/someFileName.wav"

But I needed the value, not just an assertion and this did not work:

String audio = "config.${prop}"

Or something like it.


Then, I ran across the original posting that was made to get to his findings:

println prop.tokenize( '.' ).inject( config ) { cfg, pr -> cfg[ pr ] } 

Then was finally able to close my very long week:

String audio = srcProperty.tokenize( '.' ).inject( config ) { cfg, pr -> cfg[ pr ] }

I am so glad this is solved!

Mick Knutson

Java, JavaEE, J2EE, WebLogic, WebSphere, JBoss, Tomcat, Oracle, Spring, Maven, Architecture, Design, Mentoring, Instructor and Agile Consulting. http://www.baselogic.com/blog/resume

View all posts

Java / JavaEE / Spring Boot Channel

BLiNC Supporters

BLiNC Adsense