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

将字符串传递到服务层中的grailsApplication.config,grails,properties,Grails,Properties,任何人都知道如何将字符串作为参数传递给grailsApplication.config I have tried the following. class ConfigPropertiesLoader { def grailsApplication def getProperty(String property ){ def properties=grailsApplication.config.${property} return proper

任何人都知道如何将字符串作为参数传递给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
错误2013-02-13 12:59:29850[http-bio-8080-exec-10]错误0]。[grails]-Servlet.service()为Servlet grails引发异常
消息:无法获取null对象的属性“config”
直线法
->>30 | com.nagra.ms.sam.config.ConfigPropertiesLoader$$ENxJABt5中的getProperty
|51 |在com.nagra.ms.sam.entity.account.controller.AccountController中
|196 | getBean。在grails.plugin.cache.web.filter.AbstractFilter中
|842 | grails.plugin.cache.web.filter.PageFragmentCachingFilter中的lookupController
|176 | doFilter。在“
|63 | grails.plugin.cache.web.filter.AbstractFilter中的doFilter
|1110 |运行工人。在java.util.concurrent.ThreadPoolExecutor中
|603 |在java.util.concurrent.ThreadPoolExecutor$Worker中运行
^722 |跑。在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:使用字符串作为配置名称。您可以访问反馈地址,如:

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.

希望这对您有所帮助。

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

考虑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:使用字符串作为配置名称。您可以访问反馈地址,如:

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.

如果我的答案对你有用的话,希望这对你有所帮助。我很想让人接受;)如果我的回答对你有用。我很想让人接受;)