[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

grails.enable.native2ascii

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

grails.views.default.codec

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.

grails.views.gsp.encoding

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

grails.mime.file.extensions

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

grails.mime.types

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

grails.serverURL

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

grails.views.gsp.sitemesh.preprocess

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)

bonus

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. .. ..