grailsgrails3

Grails 3.3.2 extending "NavigableMapConfig" and overriding "get" method


I have a scienario like to get dynamic config properties whenever user try to access properties from "Holders", for eg: "Holder.config.testPropertyKey.userSpecific".

I debugged this and it goes to method "get" of "NavigableMapConfig" class which implements "NavigableMap".

I tried to extend the "NavigableMapConfig" class to ovveride the "get" method and no luck.

If any one knows how to do this or need suggestion if i am in wrong path to achieve this.


Solution

  • I found the solution for this:

    In "BootStrap.groovy" file i overriden the "getConfig" for "Holders" method by the help of "Metaprogramming" as bellow:

        ExpandoMetaClass.enableGlobally();
        Holders.metaClass.static.getConfig = {
            <you code goes here...>
        }