1

The short version: How do I access Spring Boot application properties from my application context?

Here is an example of what I am trying to do. If there is a better or more standard way to do something like this, let me know.

The application.properties file:

spring.application.name = myApp
spring.profiles.active = dev

The context.groovy file:

import ...
beans {
    name String, ref('spring.application.name')
    env String, ref('spring.application.env')

    otherBean(...) {
        name = name
    }
}

I have tried a number of formats that also do not work:

name = spring.application.name
name = ref('spring.application.name')

I must be missing something fundamental about how to import or access the application properties from within the context configuration.

1 Answer 1

3

You use it with the place holder syntax (watch out to use single quotes, or else groovy will handle it), e.g.:

appName String, '${spring.application.name}'

or you have direct access to the environment (no ref &c needed). e.g.

appName String, environment.getProperty('spring.application.name', 'The Fallback')
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.