简体   繁体   中英

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.

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...>
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM