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}",
//      "classpath:${appName}-config.groovy",
//      "file:${userHome}/.grails/${appName}",
//      "file:${userHome}/.grails/${appName}-config.groovy"]

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

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

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

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.