Monday, March 9, 2009

Grails configuration issue

As far as You know Grails offers many solutions for configuration of Grails application. But most of the configuration is handled by the Config.groovy file in grails-app/conf. I used standard configurations created by default and simply added mail settings in the end of the file as was described in one of my previous posts. But when I tried to read, for instance, grails.serverURL property using grailsApplication.config at controller's layer (and even using ConfigurationHolder at service layer) I've got empty string at runtime. Part of my Config.groovy file is listed below:
environments {
development {
grails.serverURL = "http://localhost:8080"
}
}

// Some other configuration.

grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "youracount@gmail.com"
password = "yourpassword"
props = ["mail.smtp.auth":"true"]
}
}

I was quiet confused cause I still could read configuration not connected with grails, for instance, log4j settings.
As I discovered later problem lied in fact that using grails { (and open bracket) rewrited all previous settings concerning grails. So one of the correct solution might be:
environments {
development {
grails.serverURL = "http://localhost:8080"
grails.mail.host ="smtp.gmail.com"
grails.mail.port = 465
grails.mail.username = "youracount@gmail.com"
grails.mail.password = "yourpassword"
grails.mail.props = ["mail.smtp.auth":"true"]
}
}

In this case settings are added not rewrited. Don't repeat somebody's mistakes. Enjoy!

1 comment: