Spring Boot配置文件位置选择

Spring Boot学习笔记(一)构建第一个Spring Boot项目 构建第一个Spring Boot项目 Spring Boot入门介绍: BUILD ANYTHING. Spring Boot is designed to get you up and running as quickly as possible, with minimal upfront configuration of Spring. Spring Boot takes an opini... 阅读详情

Spring Boot配置文件放在jar外部

Spring Boot程序默认从application.properties或者application.yaml读取配置,如何将配置信息外置,方便配置呢?查询官网,可以得到下面的几种方案:

通过命令行指定

SpringApplication会默认将命令行选项参数转换为配置信息
例如,启动时命令参数指定:

java -jar myproject.jar --server.port = 9000

从命令行指定配置项的优先级最高,不过你可以通过setAddCommandLineProperties来禁用

SpringApplication.setAddCommandLineProperties(false)

外置配置文件

Spring程序会按优先级从下面这些路径来加载application.properties配置文件

  1. 当前目录下的/config目录
  2. 当前目录
  3. classpath里的/config目录
  4. classpath 根目录

因此,要外置配置文件就很简单了,在jar所在目录新建config文件夹,然后放入配置文件,或者直接放在配置文件在jar目录

自定义配置文件

如果你不想使用application.properties作为配置文件,怎么办?完全没问题

java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties

或者

java -jar -Dspring.config.location=D:\config\config.properties springbootrestdemo-0.0.1-SNAPSHOT.jar

当然,还能在代码里指定

@SpringBootApplication
@PropertySource(value={"file:config.properties"})
public class SpringbootrestdemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootrestdemoApplication.class, args);
    }
}

按Profile不同环境读取不同配置

不同环境的配置设置一个配置文件,例如:

  • dev环境下的配置配置在application-dev.properties中;
  • prod环境下的配置配置在application-prod.properties中。

在application.properties中指定使用哪一个文件

spring.profiles.active = dev

当然,你也可以在运行的时候手动指定:

java -jar myproject.jar --spring.profiles.active = prod

Spring Boot入门篇 | Spring Boot 1 一、什么是Spring Boot Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。用我的话来理解,就是 Spring Boot 其实不是什么新的框架,它默认配置了很多框架的使用方式,就像 Maven 整合了所有的 Jar 包,Spring ... 阅读详情

相关推荐

深入探索 SEED-VII:情感脑电图研究的新利器

SEED-VII是上海交通大学最新发布的多模态情感脑电图数据集,在传统EEG数据基础上增加了眼动、生理信号等多维信息,支持更精细的情感识别研究。该数据集提供了丰富的情感维度标注(效价和唤醒度),可用于算法基准测试、跨模态情感融合及个性化模型开发等研究场景。在应用层面,SEED-VII可推动人机交互、心理健康监测、教育娱乐等领域的情感计算技术发展。文章还提供了PyTorch加载该数据集的代码示例,为研究者使用该数据集提供了技术参考。

qq_32516809的博客 1748

Spring Boot配置文件放在jar外部

Spring Boot程序默认从application.properties或者application.yaml读取配置,如何将配置信息外置,方便配置呢? 查询官网,可以得到下面的几种方案: 通过命令行指定 SpringApplication会默认将命令行选项参数转换为配置信息 例如,启动时命令参数指定: java -jar myproject.jar --server.port =

fanhenghui的专栏 7227

【Agent】多智能体框架MetaGPT入门教程

创建一个 Action 类的子类 SimpleWriteCode,子类中定义好 prompt,并解析返回结果。在 MetaGPT 中,

酒酿小圆子呀~ 3142

SpringBoot 如何将配置文件挂到 jar 包外面?

SpringBoot 如何将配置文件挂到 jar 包外面?

ACGkaka的博客 8430

硬核拆解华为/大疆/小米硬件面试真题:手撕电路+考点思维导图(附答案)

设计一个增益为20dB、带宽≥100kHz的同相放大器,电源电压±5V,要求输出摆幅≥8V。12位ADC的参考电压2.5V,输入信号1kHz正弦波,峰峰值2V。输入24V转5V/10A的同步降压电路,开关频率500kHz,计算MOSFET的损耗并选择型号(需提供TI官网截图)。设计无人机图传系统,要求1080P@30fps,传输距离2km。FPGA设计中,100MHz时钟域到50MHz时钟域传输32位数据,给出同步方案并画时序图。“设计一个输入12V、输出5V/3A的同步降压电路,给出关键参数计算”

qq_63103361的博客 3539

Visual Studio 命令提示符工具区别与使用场景

Visual Studio会提供一系列命令提示符工具,这些工具应用在哪些场景呢?本文进行了相关介绍。

cicada15的博客 3495

spring boot指定配置文件路径

springboot配置文件

weixin_50971474的博客 5073

华为防火墙 策略路由实现多ISP接入Internet

PC3上网访问Server1时走ISP1。PC4上网访问Server1时走ISP2。1、配置接口IP并加入相应的安全区域。二、ISP2 运营商 R2路由器。一、ISP1 运营商 R1路由器。

一直被模仿,从未被超越 3016

Spring Boot配置文件放在jar外部的几种方案

springboot读取外部配置文件的方法,如下优先级: 第一种是在执行命令的目录下建config文件夹。(在jar包的同一目录下建config文件夹,执行命令需要在jar包目录下才行),然后把配置文件放到这个文件夹下。 第二种是直接把配置文件放到jar包的同级目录。 第三种在classpath下建一个config文件夹,然后把配置文件放进去。 第四种是在classpath下直接放配置文件。 springboot默认是优先读取它本身同级目录下的一个config/application.properties

Alex的博客 9539

保姆级教程:在MounRiver Studio上为CH32V307配置FreeRTOS与LwIP网络栈

本文提供了一份详细的教程,指导如何在MounRiver Studio上为CH32V307配置FreeRTOS与LwIP网络栈。从开发环境搭建到网络功能验证,涵盖了FreeRTOS内核定制、LwIP协议栈配置、硬件抽象层实现等关键步骤,帮助开发者快速掌握RISC-V架构下的嵌入式网络开发。

weixin_29275257的博客 362

(5)ModalAI VOXL2

Ardupilot官网关于《Non-GPS navigation》的翻译 —《(5) ModalAI VOXL2》。

无人机开发(开源Ardupilot) 1万+

将spring boot项目成jar包,并把配置文件等放在jar包外部

博主遇见过这种问题,在分布式项目中,我们常常会通过配置文件的更改达到部署项目,增加项目,实现负载均衡等一系列操作,我们常常用的是springboot打成的jar部署(方便快捷),要是配置文件在jar,外面不能更改,那么我们的操作将变得麻烦 注意 如果用的querydsl 必须注释 pom文件中的配置 <build> <plugins> ...

liuhm的博客 1万+

基于ENVI完成影像的去云操作以及后续处理

利用ENVI完成重采样影像的去云操作 由于SNAP重采样之后的影像是分波段保存的,ENVI的波段运算工具一次也只能输出一个波段,所以去云的操作分波段进行,原理是掩膜法 下面是打开所有波段后的界面 去云的依据是以quality_scene_classification栅格文件为基础,该文件是哨兵2数据自带的场景质量分类图,包含12个级别,可以通过SNAP软件查看,如下图所示: 对于去云操作而言,我们只需要DARK_FEATURE_SHADOW(地形等),CLOUD_SHADOW(云阴影)、CL

lemon_tttea的博客 2万+

Spring Boot 中加载多个 YAML 配置文件

Spring Boot 提供了多种方法来加载多个 YAML 配置文件,选择哪种方法取决于你的具体需求和应用场景。无论是使用、profiles、还是,都可以帮助你有效地管理和加载配置信息。

不积跬步,无以至千里;不积小流,无以成江海。 1672

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

(二)2.2 springboot配置文件详解——配置文件的默认加载位置、指定加载位置、以及它们的加载顺序and外部配置的加载顺序

一、配置文件的默认位置 以及它们的加载顺序 1、配置文件默认的存放位置 springboot启动时,默认会扫描以下几个位置的主配置文件application.properties,来进行加载。 而配置文件所放的位置不同,springboot加载的顺序就不同,配置文件可以放在如下几个地方: 项目目录下的config文件夹里 (优先级最高,最先加载) 项目目录下。 classpath:/config/ classpath:/ (优先级最低,最后被加载) 2、配置文件加载的优先级 配置位置的配置文件加载的

小码哥222的博客 667

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

properties文件_spring boot 配置文件yaml和properties

spring boot 的所有配置都在application.properties或application.yaml的文件中,配置文件生效的目录的顺序是:1、A /config 打包后jar包所在目录的目录.2、打包后的当前目录3、classpath:/config 目录4、classpath根目录默认会读取application的配置文件名,当然,默认的文件名和默认的配置文件的路径都是可以修改的...

weixin_39699912的博客 176

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

【Spring Boot教程】(一):创建第一个Spring Boot项目

操作流程 File->New->Project->Spring Initializr->Next(如果显示超时就选择Custom并填写我写的阿里云镜像) 填写相关信息->Next 选择Spring Boot版本并勾选相关依赖->Next->填写文件路径 springboot项目目录介绍 resources目录下必须有aplication.yml或application.properties核心配置文件 在Java文件夹目录下有且只有一个项目入口类,一般是项

一条小黑龙的博客 293

Spring Boot 多文件配置 及其位置

所以刚开始装配的是autoconfigration默认值—>我们可以通过xxx.properties和application.yml绑定进行自行配置。只要在依赖中找到Springbootstarter加入进去就生效了。下面还有一些失效组件原因是因为没有加载依赖。这就送我么为什么可以自动装配的原因。绑定实现配置自定义更改。......

dream1,2,3;的博客 288

properties和yaml 配置文件

常用的配置文件,有两种格式:application.properties 和 application.yaml 两种类型的文件,除了写法不同之外,用法基本相同,其中.yaml文件需要注意的是在:后面要有一个空格,如user: wdy 本节主要使用 .properties文件介绍。 位置 SpringApplication 加载配置文件的路径和顺序如下: /config/application.p......

imDony 3030

Spring Boot配置 application.yml,根据application.yml选择启动配置

在Spring Boot 中可以选择applicant.properties 作为配置文件,也可以通过在application.yml中进行配置,让Spring Boot根据你的选择进行加载启动配置文件。

好看的皮囊千篇一律,有趣的灵魂万里挑一。 1995

Spring Boot工程结构

创建了一个基本的Spring Boot工程,并在里面进行了简单的编码,实现了一个对外的。的朋友可以很快发现,这个结构就是个典型的Maven工程结构。管理的类的最外层,否则的话在启动类中要增加注解。如果是要编写微服务工程,最好还是改下后缀,使用。这个不影响我们的使用,除非你对。有特殊要求,否则这个地方可以忽略。编写单个工程的话,用这个就挺好。,有些list和map的配置在。基于上面的配置,老韩本机的。的说法,默认情况下启动类。格式里面看起来很奇怪的。应该是其他所有要交给。

分享技术,分享生活 423

spring boot 与mybatis整合(xml与注解)

目录 零、版本 一、目录树与所需jar包 二、配置文件 三、实体类 四、dao接口与注解 五、dao接口与xml文件 六、service 七、controller 零、版本 使用java1.8 mysql5.7 spring boot 1.5.20 一、目录树与所需jar包 创建spring boot时,选择 web,mybatis,jdbc,mysql...

今天吃了吗的博客 431

SpringBoot【二】yaml、properties两配置文件介绍及使用

这篇文章是关于 Spring Boot 中 yaml 和 properties 两种配置文件的介绍及使用。讲述了配置文件的存放位置及优先级,公共配置文件的使用方法,两种文件的语法差异,同时存在时的优先级选择,还给出了相关注意事项

mf97532的博客 1509

Java JAR包的`META-INF`目录下可以放置多种配置文件的整理

Java JAR包的`META-INF`目录下可以放置多种配置文件的整理

爱的叹息的专栏 1344

在springboot应用中使用dubbo-spring-boot-starter

在springboot应用中使用dubbo-spring-boot-starter开篇一. 项目结构介绍二. provider配置三. consumer配置四. 运行与其他说明 开篇 dubbo-spring-boot-starter由于比较新,也没有详实的官方资料,网上乱七八糟各种抄袭的教程很多都不靠谱,让我踩了很多很多坑。在这里我将dubbo-spring-boot-starter的使用过程如...

qq_34784720的博客 5741

【JavaEE】Spring Boot 快速上手

本文介绍了使用Spring Boot和Maven开发Java Web应用的基础知识。首先说明了Spring Boot如何简化传统Spring应用的配置流程,随后详细讲解了Maven的核心功能,包括项目构建和依赖管理。文章重点演示了Maven依赖配置方法、依赖传递机制以及如何解决依赖冲突,并介绍了Maven Helper插件的使用。此外,还解释了Maven仓库的工作原理,包括本地仓库配置和中央仓库访问。最后,文章指导读者完成了一个简单的Spring Boot Web项目创建过程,实现"Hello W

REGARD712的博客 2396
上一篇: 两数互换的三种方法
下一篇: 类加载机制学习补充
MrMoving
博客等级 码龄10年 54粉丝 145原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值