Renaming application.properties in the Spring application

Spring Boot doesn't force us to use only one properties file with the name application.properties or application.yml. It allows you to override the name of this file. For example, you could use myapp.properties as follows:

package com.dineshonjava.masteringspringboot; 
 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
 
@SpringBootApplication 
public class MasteringSpringBootApplication { 
 
   public static void main(String[] args) { 
         System.setProperty("spring.config.name", "myapp"); 
         SpringApplication.run(MasteringSpringBootApplication.class, args); 
   } 
}
The property filename must be defined as myapp, not myapp.properties; if we use myapp.properties, the file would get named as myapp.properties.properties.

As you can see in the code snippet, here, I am using the myapp.properties file instead of using the application.properties file.

Let's see how to create external application properties by using beans and how to register with the Spring application as a property file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.251.57