Chapter 7. Configuration

Grails uses a “convention over configuration” approach, but of course that doesn’t mean that everything follows a convention. You should use the conventions where they make sense and override defaults as needed. And, beyond configuring core functionality, Grails has several configuration files under the grails-app/conf folder where you configure application settings, Spring bean definitions, library and plugin dependencies, and so on. Quite often, as an application grows, these configuration files can get large and unwieldy, so in this chapter, we discuss various approaches for partitioning and organizing various config files.

External config Files

The Config.groovy file that’s generated by the create-app script contains this commented-out code at the top:

// locations to search for config files that get merged into the main config;
// config files can be ConfigSlurper scripts, Java properties files, or classes
// in the classpath in ConfigSlurper format

// grails.config.locations = [
//      "classpath:${appName}-config.properties",
//      "classpath:${appName}-config.groovy",
//      "file:${userHome}/.grails/${appName}-config.properties",
//      "file:${userHome}/.grails/${appName}-config.groovy"]

// if (System.properties["${appName}.config.location"]) {
//    grails.config.locations << "file:" +
//         System.properties["${appName}.config.location"]
// }

This provides a great way of defining one or more external config files that get merged into the main config that’s ...

Get Programming Grails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.