繁体   English   中英

将字符串传递给服务层中的grailsApplication.config

[英]pass a string to grailsApplication.config in service layer

谁能知道如何将字符串作为参数传递给grailsApplication.config。

 I have tried the following.

class ConfigPropertiesLoader {
   def grailsApplication

   def getProperty(String property ){
           def properties=grailsApplication.config.${property}

    return properties;
}

这是我得到的错误,

   Error 2013-02-13 12:59:29,850 [http-bio-8080-exec-10] ERROR 0].[grails]  -    Servlet.service() for servlet grails threw exception
   Message: Cannot get property 'config' on null object
   Line | Method
   ->>   30 | getProperty      in    com.nagra.ms.sam.config.ConfigPropertiesLoader$$ENxJABt5

   |     51 | <init>           in com.nagra.ms.sam.entity.account.controller.AccountController
   |    196 | getBean . . . .  in grails.plugin.cache.web.filter.AbstractFilter
   |    842 | lookupController in grails.plugin.cache.web.filter.PageFragmentCachingFilter
   |    176 | doFilter . . . . in     ''
   |     63 | doFilter         in grails.plugin.cache.web.filter.AbstractFilter
   |   1110 | runWorker . . .  in java.util.concurrent.ThreadPoolExecutor
   |    603 | run              in java.util.concurrent.ThreadPoolExecutor$Worker
   ^    722 | run . . . . . .  in java.lang.Thread

我不确定我是否理解您的确切问题,因此我将为您列出几种不同的解决方案:

考虑Config.groovy中的以下两个条目

feedbackAddress="xyz@abcdefg.com"

blogs = {groupName->
        if(groupName == 'IT') {
            //return blog URLs for IT folks
        } else if(groupName == 'UX') {
            //return blog URLs for UX folks
        } else {
            //return others
        }
    }

情况1:使用字符串作为配置名称。 您可以像这样访问feedbackAddress:

def feedbackAddress = grailsApplication.config["feedbackAddress"]

情况2:将参数传递给配置。 您可以列出特定组的博客,例如:

def groupName = "IT"
grailsApplication.config.blogs(groupName) //this will give you whatever's defined in the IT block of config.

希望这可以帮助..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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