We are upgrading grails 2.4.4 to 3.6.6, but the code failed at grailsApplication.config.grails.binRange. Any idea why I am not able to access grails from config. anyone can solve this?
Asked
Active
Viewed 332 times
1 Answers
1
The default configuration file for Grails 3 applications is grails-app/conf/application.yml
. In this file, YAML syntax is supported.
The GrailsApplication interface defines the getConfig
method which returns a Config object. In the Spring application context is a bean named grailsApplication
which is an instance of a class which implements the GrailsApplication
interface. Retrieving the config object from this bean is one way to gain access to config values.
For Example: grails-app/conf/application.yml
max:
line:
numbers: 42
OR
max.line.numbers: 42
grails-app/init/BootStrap.groovy
import grails.core.GrailsApplication
class YourController{
GrailsApplication grailsApplication
// retrieve the max.line.numbers config value
def maxLineNumbers = grailsApplication.config.getProperty('max.line.numbers')
}
Hope this will helps you

Rahul Mahadik
- 11,668
- 6
- 41
- 54
-
1Thank you so much Rahul, this is very useful for me. – shrikant joshi Sep 05 '18 at 12:36
-
Hi Rahul, thanks for this answer as it was also useful to me. Do you know if the configs defined in the application.yml file is accessible directly from a gsp template by doing something like ${grailsApplication.config.max.line.numbers} ? or do I have to add the bean to the respective controller in order to make it available? Thank you :) – ZvKa Mar 01 '20 at 16:28
-
1@ZvKa In gsp you can access using this `${grailsApplication.config.get('max.line.numbers')}` – Rahul Mahadik Mar 02 '20 at 04:39
-
Thanks Rahul! one last question although it's a bit unrelated but since you sound like you're a Grails expert....I'm trying to use the Assets plugin to package a javascript library, particularly the ArcGIS JS API but I have not been successful and I think that's because the library uses AMD loading. Do you know if this is a true statement? Thanks again. – ZvKa Mar 06 '20 at 07:29