I've defined an application name using the bootstrap.yml file in my spring boot application.
spring: application: name: abc
How can i get this application name during runtime/programmatically ?
On the other hand, spring.config.name can be used to change the base name of the properties file which defaults to application . The documentation reads: if you don't like application. properties as the configuration file name you can switch to another.
By default, Spring boot applications are accessed by context path “/” which is default for embedded servers i.e. we can access the application directly at http://localhost:PORT/ .
Use of @Value Annotation Note − If the property is not found while running the application, Spring Boot throws the Illegal Argument exception as Could not resolve placeholder 'spring.application.name' in value "${spring.application.name}".
In Spring Boot Reference Manual. The question asks for the application name, not the application ID. The application ID is the application name. For me, the getApplicationName() returns nothing and getApplicationId() returns the name of the application, as set with the spring.application.name property.
You should be able to use the @Value annotation to access any property you set in a properties/YAML file:
@Value("${spring.application.name}") private String appName;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With