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

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.

主站蜘蛛池模板: 文成县| 宝兴县| 壶关县| 蒙山县| 天峨县| 吴江市| 射阳县| 大名县| 电白县| 淳化县| 静乐县| 清原| 化州市| 西城区| 芦山县| 肇源县| 榕江县| 奉化市| 潼南县| 林西县| 临泉县| 云南省| 包头市| 洞头县| 达日县| 福建省| 北海市| 云阳县| 仁化县| 洪江市| 徐闻县| 阳谷县| 连平县| 兴宁市| 寿光市| 安仁县| 万年县| 武乡县| 霍城县| 双牌县| 康保县|