[Java] [Grails] Setting area and setting items of application.yml

2 minute read

Recently, I had an opportunity to use Grails at work and read the official document, so I will write about Config (including my memorandum …)

Grails settings area

Mainly divided into two areas: build settings and runtime settings

Build settings are generally done with Gradle and build.gradle. Runtime configuration is done in the grails-app/conf/application.yml file by default

  • If you want to use Grails 2.0 style settings, use Groovy’s ConfigSlurper syntax. There are two configuration files for Grails 2.0 style. ・Grails-app/conf/application.groovy ・Grails-app/conf/runtime.groovy Settings that do not depend on the application class are application.groovy, Use runtime.groovy for the settings that depend on the application class.

application.yml settings


Set this to false (default: true) if you do not need native2ascii conversion of Grails i18n properties file.


Set default encoding system of GSP One of’none’,’html’, or’base64’ (default:’none’). Set this to’html’ to reduce the risk of XSS attacks.


File encoding used for GSP source files (default:’utf-8’).


Whether to use a file extension for MIME type detection in Content Negotiation (default is true).


Settings for a map of supported MIME types for use in content negotiation.


A string that specifies the server URL portion of the absolute link, including the server name. This setting is also used for redirects. Refer to the document for details


Whether to preprocess SiteMesh. Disabling slows down page rendering, but if you need SiteMesh to parse the HTML generated from a GSP view, disable it.

grails.reload.excludes and grails.reload.include

Setting these directives determines the project-specific reload behavior of source files. Each directive receives a list of strings that represent the class names of project source files that should be excluded from or included in the reload behavior when running the application under development with the run-app command. For example, if the grails.reload.include directive is set, only the classes included in that list will be reloaded. (Grails.reload.excludes, on the contrary, reloads everything except the included class)


load application.yml settings

If you want to read the runtime settings, that is, the settings defined in application.yml, use grailsApplication object that can be used as a variable in controller or tag library. The grailsApplication object’s config property is an instance of the Config interface, It provides many methods to read the settings. For example, the getProperty method is useful for efficiently retrieving configuration properties while specifying a property type (the default type is String) and providing a default fallback value.

Accessing settings dynamically at runtime can have a small impact on application performance. Another approach is to implement the GrailsConfigurationAware interface. If you feel like this, I will add a post or post an article. .. ..