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

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.

主站蜘蛛池模板: 万州区| 循化| 二连浩特市| 英德市| 托克逊县| 泰兴市| 江都市| 阿拉善盟| 山东| 都兰县| 马龙县| 嘉祥县| 韶关市| 宜州市| 定陶县| 武宁县| 龙山县| 余姚市| 满城县| 长宁县| 大庆市| 哈密市| 怀集县| 苏尼特左旗| 巴马| 卫辉市| 武冈市| 台东市| 开封县| 赤峰市| 买车| 东阿县| 思南县| 吕梁市| 汶上县| 衡南县| 扶绥县| 西吉县| 化隆| 高平市| 拜泉县|