How to access Grails configuration in Grails 2.0?

后端 未结 6 2048
青春惊慌失措
青春惊慌失措 2020-11-30 18:35

I have obtained the latest Grails 2.0 milestone, and I am seeing a deprecation warning for the ConfigurationHolder class:

org.codehaus.groovy.gr         


        
6条回答
  •  被撕碎了的回忆
    2020-11-30 19:16

    Another non-deprecated way to get the config is:

        ApplicationContext context = ServletContextHolder.servletContext.
            getAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT) 
            as ApplicationContext
        ConfigObject config = context.getBean(GrailsApplication).config
    

    This works in situations where there is no injected parent available, such as servlet classes or static methods.

提交回复
热议问题