Reputation: 1013
I am using Grails 3.1, trying to create a custom property file and read the data present in that file.
File myapp.properties
is located in the config directory and contains data such as
name = "abc"
I want to read the data in my controller.
Any suggestions is appreciated
Upvotes: 1
Views: 893
Reputation: 7985
Easiest way is probably with Spring Boot's @ConfigurationProperties
.
Put your myapp.properties
in src/main/resources
then create a configuration class:
@ConfigurationProperties(locations=['classpath:myapp.properties'])
class MyConfiguration {
String name
}
Add it as a Spring bean in grails-app/resources.groovy
myConfiguration(MyConfiguration)
Auto wire it into a controller or service:
@Autowired
MyConfiguration myConfiguration
def foo() {
render myConfiguration.name
}
Upvotes: 3