【发布时间】:2014-09-04 07:53:02
【问题描述】:
我在 src/groovy 下有一个文件,我的 Config.groovy 和外部属性文件中也有一些属性。通常,如果想要访问属性,可以使用 grailsApplication .configuration.property.name 表达式。我希望能够从 src/groovy 目录下的这个文件中访问所有这些属性。到目前为止我所尝试的
import grails.util.Holders
class ForkedTomcatCustomizer {
def application
void customize(Tomcat tomcat) {
println Holders.grailsApplication.config.property.name
}
}
给我 NPE 说 grailsAppliction 为空
import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes as GA
class ForkedTomcatCustomizer {
def application
void customize(Tomcat tomcat) {
def ctx = SCH.servletContext.getAttribute(GA.APPLICATION_CONTEXT)
def grailsAppliction = ctx.grailsApplication.getObject()
println grailsAppliction.config.property.name
}
}
相同 - NPE,因为 grailsAppliction 为空
是否有可能以某种方式处理这种情况?谢谢!
【问题讨论】:
标签: grails grails-2.0 grails-plugin