官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 平顺县| 二连浩特市| 察雅县| 马公市| 九江市| 始兴县| 无极县| 德江县| 都江堰市| 湖北省| 巫山县| 南阳市| 积石山| 奇台县| 海兴县| 武邑县| 通许县| 庆云县| 亳州市| 越西县| 美姑县| 确山县| 湖南省| 略阳县| 三江| 新晃| 巴楚县| 皋兰县| 中牟县| 铜梁县| 莲花县| 双鸭山市| 兴安盟| 通化市| 松桃| 武清区| 千阳县| 额济纳旗| 平邑县| 南部县| 玉门市|