Search This Blog

Friday, August 28, 2020

application.properties in Spring boot

 -------------- application.properties ------------------

Properties files are used to keep ‘N’ number of properties in a single file to run the application in a different environment. In Spring Boot, properties are kept in the application.properties file under the classpath.

Note:1. application.properties  is very important file to override default values of spring boot.

2. static folder is used for static content file like   css and  js file.
3. application.properties  is case sensitive and must be accurate.

Ref doc: 1. https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/reference/html/common-application-properties.html

2.  https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html

Properties files are used to keep ‘N’ number of properties in a single file to run the application in a different environment. In Spring Boot, properties are kept in the application.properties file under the classpath.

YAML File

Spring Boot supports YAML based properties configurations to run the application. Instead of application.properties, we can use application.yml file. This YAML file also should be kept inside the classpath. The sample application.yml file is given below −

spring:
   application:
      name: demoservice
   server:
port: 9090

Externalized Properties

Instead of keeping the properties file under classpath, we can keep the properties in different location or path. While running the JAR file, we can specify the properties file path. You can use the following command to specify the location of properties file while running the JAR −

   What is Class SpringApplicationBuilder

In our application we have used SpringApplicationBuilder in the starter application. starter is an simple application which will start the actual application instances programatically.

The number of processes to be started and type of process web/standalone will be passed as an argument to starter application, based on the arguments the application instances will be started. we have used -w to start as web application for state management.

boolean isWeb = // options parser, parse -w
new SpringApplicationBuilder(SpringBootAngularApp.class).web(isWeb).run(args);

There is another way of doing the same

SpringApplication sp = new SpringApplication(SpringApplicationBuilder.class);       
sp.setWebEnvironment(false);
sp.run(args);

We can also customise banner, loggers with SpringApplicationBuilder.



Ref doc: https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/builder/SpringApplicationBuilder.html

No comments:

Post a Comment