2010-12-15 10 views

cevap

6
import grails.util.Environment 

class BootStrap { 

    def init = { servletContext -> 

     def currentEnv = Environment.current 

     if (currentEnv == Environment.DEVELOPMENT) { 
      // do custom init for dev here 

     } else if (currentEnv == Environment.TEST) { 
      // do custom init for test here 

     } else if (currentEnv == Environment.PRODUCTION) { 
      // do custom init for prod here 
     } 
    } 

    def destroy = { 
    } 
} 
+7

Bu eski yöntem. Şimdi Grails, BootStrap.groovy'de olduğu gibi Config.groovy ve DataSource.groovy'de olduğu gibi bir 'environments' bloğunu desteklemektedir - docs bölüm 3.2'de" Ortam Bootstrapping'in Başına "bakın. –

0

Programlı Çevre Algılama böyle bir Gant komut dosyası veya bir önyükleme sınıfına Eğer GrailsUtil sınıfını kullanarak çevreyi algılayabilir gibi Kodunuzdaki içinde

:

import grails.util.GrailsUtil 
... 
switch(GrailsUtil.environment) { 
    case "development": 
     configureForDevelopment() 
    break 
    case "production": 
     configureForProduction() 
    break 
the documentation itibaren
14

:

class Bootstrap { 
    def init = { ServletContext ctx -> 
     environments { 
      production { 
       // prod initialization 
      } 
      test { 
       // test initialization 
      } 
      development { 
       // dev initialization 
      } 
     } 
    } 
    ... 
}