Ashu
Ashu

Reputation: 402

config.groovy meare with .property file in grails

In my config.groovy i have set ..

emailTo="[email protected]" emailForm="[email protected]"

but i want some flexibility in this. Can I change this while my project is running form property file ? Please help

Upvotes: 1

Views: 1412

Answers (2)

Ian Roberts
Ian Roberts

Reputation: 122364

I believe there is a plugin to support dynamic reloading of external config files whenever they change, but conceptually if this is data that is supposed to be modifiable at runtime then maybe it would be better to represent it as a domain object and store it in the database.

I use this method on a number of projects, defining a domain class

class AppConfiguration {
  String adminEmail
  String appTitle
  // etc
}

and ensuring there is always exactly one instance in the database, creating an initial instance in BootStrap if it is not already present. Now anywhere in the app that requires this config data I just do AppConfiguration.list()[0]

I just use dynamic scaffolding for the edit pages, which are restricted to be accessible only to admin users through Spring Security.

Upvotes: 1

Igor Artamonov
Igor Artamonov

Reputation: 35961

Yes, you can use .property file as well, by default Grails looks for properties at:

  • in calss path ${appName}-config.properties
  • and global config ~/.grails/${appName}-config.properties
  • path passed as a system vaiable named ${appName}.config.location

Just take a look at first few lines of your Config.groovy, you can put there any other path to your own .properties

See also http://grails.org/doc/2.1.0/guide/conf.html#configExternalized

Upvotes: 1

Related Questions