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

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.

主站蜘蛛池模板: 南充市| 宜川县| 鞍山市| 东阿县| 永新县| 富源县| 汉源县| 巴塘县| 芜湖市| 静乐县| 濮阳市| 秦皇岛市| 博客| 邳州市| 获嘉县| 织金县| 自贡市| 新建县| 霍邱县| 定日县| 治县。| 迁西县| 内乡县| 龙胜| 丰县| 鸡西市| 鸡东县| 霍林郭勒市| 黔江区| 闽清县| 建瓯市| 兴城市| 城步| 基隆市| 剑河县| 鄂州市| 高碑店市| 仲巴县| 淮北市| 普兰店市| 安康市|