naresh naresh - 9 months ago 32
Groovy Question

how to access config.groovy values in src/java file?

I am not able to access config.groovy properties in java file
I wrote it like this:

ConfigObject holder = ConfigurationHolder.getConfig() ;
private String configEndPoint = holder.getProperty( "mks.elasticCache.endPoint" ).toString() ;


But values coming as null.

Answer Source

I think you want the flatConfig, not the config. In any matter assuming you are on Grails 2+, ConfigurationHolder is deprecated.

You should be able to replace the above with:

import grails.util.Holders ;

...

String endpoint = Holders.getFlatConfig()
                         .get( "mks.elasticCache.endPoint" )