application.properties

application.properties是spring boot默认的配置文件,spring boot默认会在以下两个路径搜索并加载这个文件
src\main\resources
src\main\resources\config

配置系统参数
在application.properties中可配置一些系统参数,spring boot会自动加载这个参数到相应的功能,如下
#端口,默认为8080
server.port=80
#访问路径,默认为/
server.context-path=/test
#输出日志文件,默认不输出
logging.file=/log.txt
#修改日志级别,默认为INFO
logging.level.root=DEBUG

自定义properties文件

在spring boot启动类或配置类中添加以下注解,可在启动时载入自定义的配置文件
@PropertySource("classpath:config/xxx.properties")
如果要同时载入多个文件
@PropertySource(value={"classpath:config/a.properties","classpath:config/b.properties"})

自定义参数
以自命名配置一些参数,如
key1=values1
key2=values2

在JAVA代码中,使用@Value注解,在项目启动时会将自定义参数加载到全局变量,如下

@RestController
public class SampleController {
@Value(value="${key1}")
private String key;

批量注入到类变量
在properties中配置两个以a为前缀的参数
a.key1=values1
a.key2=values2
在JAVA中用@ConfigurationProperties 将以a为前缀的参数注入到当前变量中,需要有setXxx()方法
@RestController
@ConfigurationProperties(prefix = "a")
public class SampleController {
private String key1;
private String key2;
public void setKey1(String key1) {
this.key1 = key1;
}
public void setKey2(String key2) {
this.key2 = key2;
}



spring boot(5)-properties参数配置的更多相关文章

  1. 【Quartz】Spring Boot使用properties文件配置Quartz

    (1)在resource目录下新建quartz.properties文件 #============================================================== ...

  2. spring boot application.properties基本配置

    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://loca ...

  3. 【转】spring boot application.properties 配置参数详情

    multipart multipart.enabled 开启上传支持(默认:true) multipart.file-size-threshold: 大于该值的文件会被写到磁盘上 multipart. ...

  4. Spring boot application.properties 配置

    原文链接: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.ht ...

  5. Spring Boot之实现自动配置

    GITHUB地址:https://github.com/zhangboqing/springboot-learning 一.Spring Boot自动配置原理 自动配置功能是由@SpringBootA ...

  6. Spring Boot实践——用外部配置填充Bean属性的几种方法

    引用:https://blog.csdn.net/qq_17586821/article/details/79802320 spring boot允许我们把配置信息外部化.由此,我们就可以在不同的环境 ...

  7. Spring Boot 支持多种外部配置方式

    Spring Boot 支持多种外部配置方式 http://blog.csdn.net/isea533/article/details/50281151 这些方式优先级如下: 命令行参数 来自java ...

  8. Spring Boot启动命令参数详解及源码分析

    使用过Spring Boot,我们都知道通过java -jar可以快速启动Spring Boot项目.同时,也可以通过在执行jar -jar时传递参数来进行配置.本文带大家系统的了解一下Spring ...

  9. Spring boot Security 登陆安全配置

    实现的效果 访问url时,如果未登录时跳转到Login界面,要求用户登陆,如果登陆过返回请求的数据. 效果图 访问数据时,未登录返回login界面 登陆操作 登陆成功进入登出界面 登陆成功后再次访问数 ...

随机推荐

  1. docker + nginx 部署vuejs3.0项目

    1:用指令 npm run build 打包vusjs项目(该项目是在github上下载的).打包成功后会生成一个目录dist. 2:把该文件夹拷贝到腾讯云服务器(操作系统 centos7)下的/us ...

  2. 【文档】三、Mysql Binlog事件类文件和类型

    在内部,服务器使用C++类文件来表示binlog事件.标准在log_event.h文件中,这些类的方法代码在log_event.cc中. log_event是基础类.其他的详细的事件子类都是来源于他. ...

  3. 【Kafka】Kafka集群搭建

    一.准备工作 服务器:最好是多台,大于等于2 已经搭建好的zookeeper集群 下载软件kafka_2.11-0.10.0.1.tgz 二.创建目录 #创建目录 cd /opt/ mkdir kaf ...

  4. AutoMapper控件

    1.下载AutoMapper控件. 2.定义类,实现Profile. 3.在定义类的构造方法中使用如下代码进行转换 // 1.匹配,o,t代表TDestination;s代表TSource,返回TDe ...

  5. python pip 安装OpenCV

    cmd pip install opencv-contrib-python -i https://pypi.mirrors.ustc.edu.cn/simple/

  6. PHP之string之ltrim()函数使用

    ltrim (PHP 4, PHP 5, PHP 7) ltrim - Strip whitespace (or other characters) from the beginning of a s ...

  7. C 标准库 - ctype.h

    C 标准库 - ctype.h This header declares a set of functions to classify and transform individual charact ...

  8. SQL语句实现不存在即插入,存在则increase某字段的功能insert into … on duplicate key update

    前提条件:必须是唯一主键: CREATE UNIQUE INDEX idx_vote_object ON test_customers_vote (`vote_object`, `vote_objec ...

  9. ORCLE报错解决(ora-01747:无效的用户.表.列,表.列)

    原因: 这个问题出现是因为表中存在关键字造成.

  10. 基础语言知识C++

    强制转换: (Cplusplus基础与提高(何桂林)21页) static_cast:有隐式转换的 格式: static_cast<目标类型> (标识符) int a = 10; int ...