Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a Spring Boot Application's name programmatically?

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 ?

like image 919
yathirigan Avatar asked Jul 15 '15 11:07

yathirigan


People also ask

What is spring config name?

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.

Where is spring boot application URL?

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/ .

How do you name a spring boot application?

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}".

How do I know my 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.


1 Answers

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; 
like image 125
Daniel Cottone Avatar answered Sep 28 '22 12:09

Daniel Cottone