How to access Grails configuration in Grails 2.0?

后端 未结 6 2051
青春惊慌失措
青春惊慌失措 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:15

    You can access grails configuration

    1. In Controller

      class DemoController {
          def grailsApplication
      
          def demoAction = {
              def obj = grailsApplication.config.propertyInConfig
          }
      }
      
    2. In services :

      class DemoService {
          def grailsApplication
      
          def demoMethod = {
              def obj = grailsApplication.config.propertyInConfig
          }
      }
      
    3. In taglib :

      class DemoTaglib {
          def grailsApplication
      
          static namespace = "cd"
      
          def demoMethod = {
      
              def obj = grailsApplication.config.propertyInConfig
      
              out << obj    
          }
      }
      

    You can call this method of taglib in view as

    1. In view :

       
           Demo
       
           ${grailsApplication.config.propertyInConfig}
       
      
       
      

提交回复
热议问题