Daniel Kreuter
Daniel Kreuter

Reputation: 83

Accessing property placeholders in grails3 resources.groovy doesn't work

According to the grails spring documentation (https://grails.github.io/grails-doc/3.0.3/guide/spring.html#propertyPlaceholderConfiguration) I'm trying to access some of my properties which are defined inside an external .yml file (f.e. database.user) from inside the resources.groovy file.

I tried the following:

def username = "${grailsApplication.config.dataSource.username}"

Inside the application.yml this property is defined the following way:

dataSource:
    username: ${database.username}

This configuration works everywhere inside grails3 except for resources.groovy.

Is there any way to access the resolved property? Or is there an alternative way of defining custom connection pools in grails 3 I'm not aware of?

Regards

Upvotes: 3

Views: 815

Answers (1)

Daniel Kreuter
Daniel Kreuter

Reputation: 83

Ok I found the solution to my problem.

Inside of application.yml the placeholder ${database.username} has to be defined in the following way:

database:
    username: ${database.username}

And inside of resources.groovy:

def username = "${grailsApplication.config.database.username}"

Then everything works.

Hope this helps someone else who stumbles upon this problem.

Upvotes: 5

Related Questions