How to create a custom environment in Grails?

前端 未结 3 1299
失恋的感觉
失恋的感觉 2020-12-16 16:15

grails.util.Environment, defines a number of preconfigured environments

  • DEVELOPMENT
  • PRODUCTION
  • TEST
  • CUSTOM

When runni

相关标签:
3条回答
  • 2020-12-16 16:31

    These environment-specific closures can be used in Bootstrap.groovy and Config.groovy, are there other places?

    I don't think so... For other places, you would need to use the Generic Per Environment Execution block

    Environment.executeForCurrentEnvironment {
        production {
            // do something in production
        }
        development {
            // do something only in development
        }
        pre_production {
            // do something for your custom environment
        }
    }
    

    Also, is it possible for me to define my own environment, e.g. PRE_PRODUCTION, such that it will work with the closures above and the -Denv flag?

    Yeah, you should be able to just declare -Dgrails.env=pre_production and include the pre_production block in Bootstrap.groovy or Config.groovy (or a custom grails.util.Environment block as above)

    edit

    As you can see in the Grails source for Environment, this sort of custom environment will enumerate to Environment.CUSTOM, and then in the Environment.executeForCurrentEnvironment block, it will check against CUSTOM, and the name of the custom environment

    0 讨论(0)
  • 2020-12-16 16:44

    -Dgrails.env=pre_production

    more here https://grails.org/wiki/Environments

    0 讨论(0)
  • 2020-12-16 16:56

    If you create a custom environment, you can use it anywhere that the environments {} block is used. For example, in addition to Bootstrap.groovy and Config.groovy, you can also use it in DataSource.groovy and even other Config files like Searchable.groovy.

    Also, I believe

    Environment.currentEnvironment.name will return 'pre_production' in your case.

    0 讨论(0)
提交回复
热议问题