Where to put the Constants class, available throughout the Grails application?

I have a simple question, but google and stackoverflow results did not satisfy me at all.

How to define the Constants class as:

public class Constants { public static final int SYSTEM_USER_ID = 1; } 

which can be called everywhere with Constants.SYSTEM_USER_ID

I tried it in grails-app/utils and src/java , but, for example, I could not access the Service class.

+4
source share
2 answers

You need to put your Constants class in a package. Grails cannot find a class if it is not in the package itself.

+6
source

Perhaps you put these constants in Config.groovy , and not in a class. One of the advantages of this approach is that you can specify values ​​for each environment for these constants. You can read the values ​​of these values ​​using either the implicit grailsApplication variable or the ConfigurationHolder class.

+16
source

All Articles