亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

springboot多環(huán)境配置文件及自定義配置文件路徑詳解

 更新時間:2023年02月08日 09:49:34   作者:『梧桐雨』  
這篇文章主要介紹了springboot多環(huán)境配置文件及自定義配置文件路徑,文中給大家介紹了classpath的基本概念講解及自定義springboot配置文件路徑的相關(guān)知識,需要的朋友可以參考下

一:什么是classpath?

classpath指的就是 *.java文件,資源文件等編譯后存放的位置,對于maven項目就是指 target/classes:這個路徑,只要編譯后的文件在這個目錄下,springboot就可以找到,這里指的是maven項目,javaWeb項目可能會有區(qū)別。

在這里插入圖片描述

二、自定義springboot配置文件路徑

springboot項目配置文件application.properties或者application.yml配置文件默認放置的位置是 **“classpath:/,classpath:/config/,file:./,file:./config/ ”**這4個位置。只要我們編譯后的文件位于這4個位置,springboot就可以加載配置文件。

但有時候我們需要以環(huán)境名稱為標識,配置多個環(huán)境的配置文件。如下我們需要配置dev1、dev2、stg1、stg2、prd 共5個環(huán)境,每個環(huán)境下分別配置我們的application.properties,數(shù)據(jù)庫配置,redis配置,日志配置等配置。

在這里插入圖片描述

這時我們的資源文件的路徑已經(jīng)不再是springboot默認的配置路徑了,因此springboot啟動時將無法加載配置文件,這里就需要我們在啟動類中手動指定配置文件的加載路徑了。如下:

public class DemoApplication  {
    public static void main(String[] args) {
         //springboot默認的配置文件路徑
        // String addClassPath = "spring.config.location:classpath:/";
         //自定義的配置文件路徑
        String addClassPath = "spring.config.additional-location:classpath:/";
        addClassPath += ",classpath:/config/";
        addClassPath += ",classpath:/config/dev1/";
        addClassPath += ",classpath:/config/dev2/";
        addClassPath += ",classpath:/config/stg1/";
        addClassPath += ",classpath:/config/stg2/";
        addClassPath += ",classpath:/config/prd/";
        new SpringApplicationBuilder(DemoApplication.class).properties("spring.config.name:application", addClassPath).build().run(args);
    }

springboot的加載配置項在ConfigFileApplicationListener類中,可以自行翻看下源碼定義。如下是我們從spring源碼中復(fù)制過來的一分部,可以發(fā)現(xiàn)一些我們熟悉默認配置定義,如spring.profiles.active、classpath:/,classpath:/config/,file:./,file:./config/、spring.config.name等。

public class ConfigFileApplicationListener
		implements EnvironmentPostProcessor, SmartApplicationListener, Ordered {
		
	private static final String DEFAULT_PROPERTIES = "defaultProperties";

	// Note the order is from least to most specific (last one wins)
	private static final String DEFAULT_SEARCH_LOCATIONS = "classpath:/,classpath:/config/,file:./,file:./config/";

	private static final String DEFAULT_NAMES = "application";

	private static final Set<String> NO_SEARCH_NAMES = Collections.singleton(null);

	/**
	 * The "active profiles" property name.
	 */
	public static final String ACTIVE_PROFILES_PROPERTY = "spring.profiles.active";

	/**
	 * The "includes profiles" property name.
	 */
	public static final String INCLUDE_PROFILES_PROPERTY = "spring.profiles.include";

	/**
	 * The "config name" property name.
	 */
	public static final String CONFIG_NAME_PROPERTY = "spring.config.name";

	/**
	 * The "config location" property name.
	 */
	public static final String CONFIG_LOCATION_PROPERTY = "spring.config.location";

	/**
	 * The "config additional location" property name.
	 */
	public static final String CONFIG_ADDITIONAL_LOCATION_PROPERTY = "spring.config.additional-location";

	/**
	 * The default order for the processor.
	 */
	public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 10;

	/**
	 * Name of the application configuration {@link PropertySource}.
	 */
	@Deprecated
	public static final String APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME = "applicationConfigurationProperties";

	private final DeferredLog logger = new DeferredLog();

	private String searchLocations;

	private String names;

	private int order = DEFAULT_ORDER;
      。。。。。。。。。(略)

到此這篇關(guān)于springboot多環(huán)境配置文件及自定義配置文件路徑的文章就介紹到這了,更多相關(guān)springboot多環(huán)境配置文件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 封裝jndi操作ldap服務(wù)器的工具類

    封裝jndi操作ldap服務(wù)器的工具類

    這篇文章主要介紹了封裝JNDI操作LDAP服務(wù)器的工具類,使用者只需要會使用List,Map 數(shù)據(jù)結(jié)構(gòu),大家參考使用吧
    2014-01-01
  • SpringMVC使用自定義驗證器進行數(shù)據(jù)驗證的方法

    SpringMVC使用自定義驗證器進行數(shù)據(jù)驗證的方法

    SpringMVC?提供了強大的數(shù)據(jù)驗證機制,可以方便地驗證表單提交的數(shù)據(jù),除了自帶的驗證器之外,SpringMVC?還支持自定義驗證器,允許開發(fā)者根據(jù)業(yè)務(wù)需求自定義驗證規(guī)則,本文將介紹如何在?SpringMVC?中使用自定義驗證器
    2023-07-07
  • SpringBoot Redis批量存取數(shù)據(jù)的操作

    SpringBoot Redis批量存取數(shù)據(jù)的操作

    這篇文章主要介紹了SpringBoot Redis批量存取數(shù)據(jù)的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Java 實現(xiàn)word模板轉(zhuǎn)為pdf

    Java 實現(xiàn)word模板轉(zhuǎn)為pdf

    這篇文章主要介紹了Java 實現(xiàn)word模板轉(zhuǎn)為pdf的方法,幫助大家更好的理解和學習使用Java,感興趣的朋友可以了解下
    2021-02-02
  • 大數(shù)組元素差異removeAll與Map效率對比

    大數(shù)組元素差異removeAll與Map效率對比

    這篇文章主要介紹了大數(shù)組元素差異removeAll與Map效率對比,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-03-03
  • 使用maven?shade插件解決項目版本沖突詳解

    使用maven?shade插件解決項目版本沖突詳解

    這篇文章主要為大家介紹了使用maven?shade插件解決項目版本沖突詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • springmvc+shiro+maven 實現(xiàn)登錄認證與權(quán)限授權(quán)管理

    springmvc+shiro+maven 實現(xiàn)登錄認證與權(quán)限授權(quán)管理

    Shiro 是一個 Apache 下的一開源項目項目,旨在簡化身份驗證和授權(quán),下面通過實例代碼給大家分享springmvc+shiro+maven 實現(xiàn)登錄認證與權(quán)限授權(quán)管理,感興趣的朋友一起看看吧
    2017-09-09
  • RestTemplate對HttpClient的適配源碼解讀

    RestTemplate對HttpClient的適配源碼解讀

    這篇文章主要為大家介紹了RestTemplate對HttpClient的適配源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-10-10
  • 詳解mybatis如何實現(xiàn)進行分表

    詳解mybatis如何實現(xiàn)進行分表

    在數(shù)據(jù)庫設(shè)計中,分表是一種常見的優(yōu)化策略,它可以將一個大表拆分成多個小表,以提高查詢性能和存儲效率,下面我們就來學習一下mybatis如何實現(xiàn)進行分表吧
    2023-11-11
  • Java Stream 流實現(xiàn)合并操作示例

    Java Stream 流實現(xiàn)合并操作示例

    這篇文章主要介紹了Java Stream 流實現(xiàn)合并操作,結(jié)合實例形式詳細分析了Java Stream 流實現(xiàn)合并操作原理與相關(guān)注意事項,需要的朋友可以參考下
    2020-05-05

最新評論