SpringBoot 学习记录(八): properties 属性自定义

SpringBoot踩坑记录:玩转@Value注解-自定义PropertySourcesPlaceHolderConfigurer 背景 开发环境:SpringBoot + IDEA 因特殊情况需要,有部分配置项不能直接陪在配置文件properties中,需要从枚举中获取。 这部分配置项以前是配在properties文件中的,现在需要改写到枚举中。 因此service中无法用@Value注解自动注入这些值,需要用新的方式实现注入,且尽量减少代码改动量。 解决方法 ... 阅读详情

这篇我们来学习如何在java bean 中使用我们自定义的属性

一,引入依赖包

<!-- 支持自定义配置参数 -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-configuration-processor</artifactId>
	<optional>true</optional>
</dependency>
二,在application.properties中自定义属性参数,这里分几种情况

1) 单个属性参数

先在application.properties中定义几个属性:

com.demo.title=big.title
com.demo.description=test
com.demo.num=${random.int}  
com.demo.value=${random.value}
com.demo.msg=\u6D4B\u8BD5\u6807\u9898\uFF1A${com.demo.title}
这里说明一下:

num:可以使用random生成随机数,引用方法有

${random.int}

${random.long}

${random.int(10)} == 10以内的随机数

${random.int[10,20]} == 10-20的随机数

value:可以使用random生成随机字符串(32位)

msg:可以引用文件内部定义的属性值,引用方法${key}

新建java类DemoProperties,注入自定义的属性值,这里主要使用注解@Value

package com.example.properties;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component//交由spring管理
public class DemoProperties {
	
	/**
	 * 给定一个默认值,当读取不到key值com.demo.title时启用默认值
	 */
	@Value("${com.demo.title:default.title}")
	private String title;
	
	/**
	 * 没有给定默认值,当读取不到key值时会抛异常
	 */
	@Value("${com.demo.description}")
	private String description;
	
	/**
	 * 随机数
	 */
	@Value("${com.demo.num}")
	private String num;
	
	/**
	 * 随机字符串
	 */
	@Value("${com.demo.value}")
	private String value;
	
	/**
	 * 内部引用属性
	 */
	@Value("${com.demo.msg}")
	private String msg;
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getNum() {
		return num;
	}
	public void setNum(String num) {
		this.num = num;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}

	
}
新建测试类ConfigController
package com.example.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.base.ReturnResult;
import com.example.constant.ReturnConstant;
import com.example.properties.ConfigProperties;
import com.example.properties.DemoProperties;

/**
 * 测试读取自定义属性
 * @author Administrator
 *
 */

@RestController
@RequestMapping("/properties")
public class ConfigController {

	@Resource
	private DemoProperties demoProperties;
		
	@RequestMapping("/demo")
	public ReturnResult getDemoProp(){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("demo", demoProperties);
		ReturnResult r = new ReturnResult();
		r.setStatus(ReturnConstant.RETURN_OK);
		r.setMsg("自定义单个属性");
		r.setResult(map);
		return r;
	}
	
}
访问测试: http://localhost:8088/spring-boot/properties/demo

返回结果如下:

{
  "status": "true",
  "msg": "自定义单个属性",
  "result": {
    "demo": {
      "title": "big.title",
      "description": "test",
      "num": "2050553421  ",
      "value": "09f706565ea9d4a961278578039e073f",
      "msg": "测试标题:big.title"
    }
  }
}
2) 多个属性参数

先在application.properties中定义几个属性:

com.conf.group.name=group
com.conf.group.number=10
com.conf.group.system=\u4EBA\u5458\u7BA1\u7406
com.conf.group.local-path=127.0.0.1:8080
com.conf.group.user[0]=Lily
com.conf.group.user[1]=Sam
com.conf.group.user[2]=Jessie
这里说明一下:

属性local-path不符合java命名规范,注入时参数名可以用localPath来匹配

属性user是定义的一个数组,注入时用list来接收参数

新建java类ConfigProperties,注入自定义的属性值,这里主要使用注解@ConfigurationProperties

package com.example.properties;

import java.util.List;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import com.example.entity.TestUser;

@Component//交由spring管理
//prefix设置key的前缀;
@ConfigurationProperties(prefix="com.conf.group")
public class ConfigProperties {

	/**
	 * 属性后缀要对应配置文件中设置的key
	 * key值有-连接符的可以自动匹配为java规范命名
	 * 定义的数组用集合封装 
	 */
	
	private String name;
	
	private int number;
	
	private String system;
	
	private String localPath;
	
	private List<String> user;
	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public String getSystem() {
		return system;
	}

	public void setSystem(String system) {
		this.system = system;
	}

	public String getLocalPath() {
		return localPath;
	}

	public void setLocalPath(String localPath) {
		this.localPath = localPath;
	}

	public List<String> getUser() {
		return user;
	}

	public void setUser(List<String> user) {
		this.user = user;
	}
	
}
在ConfigController中添加测试方法:
package com.example.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.base.ReturnResult;
import com.example.constant.ReturnConstant;
import com.example.properties.ConfigProperties;
import com.example.properties.DemoProperties;

/**
 * 测试读取自定义属性
 * @author Administrator
 *
 */

@RestController
@RequestMapping("/properties")
public class ConfigController {

	@Resource
	private DemoProperties demoProperties;
	
	@Resource
	private ConfigProperties configProperties;
	
	@RequestMapping("/demo")
	public ReturnResult getDemoProp(){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("demo", demoProperties);
		ReturnResult r = new ReturnResult();
		r.setStatus(ReturnConstant.RETURN_OK);
		r.setMsg("自定义单个属性");
		r.setResult(map);
		return r;
	}
	
	@RequestMapping("/conf")
	public ReturnResult getConfProp(){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("conf", configProperties);
		ReturnResult r = new ReturnResult();
		r.setStatus(ReturnConstant.RETURN_OK);
		r.setMsg("自定义多个属性");
		r.setResult(map);
		return r;
	}
}
启动服务,访问测试: http://localhost:8088/spring-boot/properties/conf

返回结果如下:

{
  "status": "true",
  "msg": "自定义多个属性",
  "result": {
    "conf": {
      "name": "group",
      "number": 10,
      "system": "人员管理",
      "localPath": "127.0.0.1:8080",
      "user": [
        "Lily",
        "Sam",
        "Jessie"
      ]
    }
  }
}
三,除了在默认的application.properties中定义属性,我们还可以自定义一个properties文件

config.properties

com.conf.group.name=group
com.conf.group.number=5
com.conf.group.system=\u4EBA\u5458\u7BA1\u7406
com.conf.group.local-path=127.0.0.1:8088
com.conf.group.user[0]=Lucy
com.conf.group.user[1]=Susan
com.conf.group.user[2]=Joly
这里方便测试,属性key值没有变,只是改变了value值

那么给java类ConfigProperties注入属性值时如何指定配置文件呢?

很简单,只需要在注解@ConfigurationProperties中添加一个属性:locations="classpath:config.properties"

@Component//交由spring管理
//prefix设置key的前缀;
@ConfigurationProperties(prefix="com.conf.group",locations="classpath:config.properties")
public class ConfigProperties {
	
}
启动测试,看是否读取的是config.properties中的属性值

http://localhost:8088/spring-boot/properties/conf

查看返回结果:

{
  "status": "true",
  "msg": "自定义properties文件,定义多个属性",
  "result": {
    "conf": {
      "name": "group",
      "number": 5,
      "system": "人员管理",
      "localPath": "127.0.0.1:8088",
      "user": [
        "Lucy",
        "Susan",
        "Joly"
      ]
  }
}

可以看到,读取到的属性值确实已经改变了。

四,在配置文件中我们还可以定义一个对象的属性值,首先在 config.properties中添加如下属性:
com.conf.group.testUser.name=user_name
com.conf.group.testUser.age=22
com.conf.group.testUser.gender=M
这里的属性值testUser将由一个自定义的对象来接收,

我们定义一个普通java类TestUser,在其中定义匹配的属性名

package com.example.entity;

/**
 * 自定义属性可以用实体类来接收
 * @author Administrator
 *
 */
public class TestUser {

	private String name;
	
	private int age;
	
	private String gender;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}
	
	
}
在ConfigProperties中添加属性:
        private TestUser testUser;

	public TestUser getTestUser() {
		return testUser;
	}

	public void setTestUser(TestUser testUser) {
		this.testUser = testUser;
	}
再来测试: http://localhost:8088/spring-boot/properties/conf

返回结果如下:

{
  "status": "true",
  "msg": "自定义properties文件,定义多个属性",
  "result": {
    "conf": {
      "name": "group",
      "number": 5,
      "system": "人员管理",
      "localPath": "127.0.0.1:8088",
      "user": [
        "Lucy",
        "Susan",
        "Joly"
      ],
      "testUser": {
        "name": "user_name",
        "age": 22,
        "gender": "M"
      }
    }
  }
}
五,以上都是通过java类直接注入属性值,下面我们来看如何在注入bean的时候注入自定义属性

1) 删除ConfigProperties的类注解,使其成为一个普通java类

package com.example.properties;

import java.util.List;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import com.example.entity.TestUser;

//@Component//交由spring管理
//prefix设置key的前缀;
//@ConfigurationProperties(prefix="com.conf.group",locations="classpath:config.properties")
public class ConfigProperties {

	/**
	 * 属性后缀要对应配置文件中设置的key
	 * key值有-连接符的可以自动匹配为java规范命名
	 * 定义的数组用集合封装 
	 */
	
	private String name;
	
	private int number;
	
	private String system;
	
	private String localPath;
	
	private List<String> user;
	
	private TestUser testUser;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public String getSystem() {
		return system;
	}

	public void setSystem(String system) {
		this.system = system;
	}

	public String getLocalPath() {
		return localPath;
	}

	public void setLocalPath(String localPath) {
		this.localPath = localPath;
	}

	public List<String> getUser() {
		return user;
	}

	public void setUser(List<String> user) {
		this.user = user;
	}

	public TestUser getTestUser() {
		return testUser;
	}

	public void setTestUser(TestUser testUser) {
		this.testUser = testUser;
	}

	
}
2) 在DemoApplication启动类中注入bean,完整代码如下:
package com.example;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

import com.example.properties.ConfigProperties;

@SpringBootApplication
@MapperScan("com.*.mapper")//扫描该包下接口
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
	
	@Bean
	@ConfigurationProperties(prefix="com.conf.group",locations="classpath:config.properties")
	public ConfigProperties configProperties(){
		return new ConfigProperties();
	}
}
启动测试: http://localhost:8088/spring-boot/properties/conf

查看返回结果:

{
  "status": "true",
  "msg": "自定义properties文件,定义多个属性",
  "result": {
    "conf": {
      "name": "group",
      "number": 5,
      "system": "人员管理",
      "localPath": "127.0.0.1:8088",
      "user": [
        "Lucy",
        "Susan",
        "Joly"
      ],
      "testUser": {
        "name": "user_name",
        "age": 22,
        "gender": "M"
      }
    }
  }
}
可以看到,这里的结果跟上面是一样的,说明注入属性成功。

===========================================================================

关于自定义属性的学习就到此结束,参考博文:http://412887952-qq-com.iteye.com/blog/2311017

下篇我们将学习,SpringBoot 学习记录(九): Email
























4. Spring Boot 2.x 最佳实践之自定义Properties Spring Boot 中自定义属性是一个非常常用的技术。 阅读详情

相关推荐

Xcelium XRUN实用指南:从入门到高效仿真

本文是Xcelium XRUN仿真工具的实用指南,从基础入门到高效应用全面解析。XRUN作为Cadence Xcelium的统一命令行入口,能自动化编译、精细和仿真流程,大幅提升数字芯片与FPGA验证效率。文章详细介绍了最简命令、波形调试、增量编译、多核并行仿真等核心功能,并提供了管理复杂项目、性能调优与深度调试的进阶技巧,帮助工程师快速上手并精通这一高效仿真工具。

weixin_29238147的博客 740

springboot自定义properties配置文件

springboot虽然免除了绝大部分的配置文件设置,但是对于一些特定情况,还是有定义配置文件的需要。 一、配置文件的格式 SpringBoot可以识别.yml和.properties两种格式的配置文件。如果是自带classpath下的application.properties和application.yml,这两种都可以被SpringBoot自动识别并加载。

西木风落 2602

保姆级教程:用再生龙Clonezilla Live给Ubuntu系统做全盘备份与恢复(含BIOS设置避坑)

本文提供了一份详细的Clonezilla Live教程,指导Ubuntu用户如何轻松完成全盘备份与恢复。从启动盘制作、BIOS设置避坑到备份参数解析和恢复操作,涵盖了所有关键步骤和常见问题解决方案,帮助用户高效保护系统数据。

weixin_42116058的博客 639

spring boot 自定义properties使用详解

(1) 在application.properties文件中添加自定义属性(单个属性使用);        在这里我们新建一个maven java project进行测试,取名为:spring-boot-hello4。 对pom.xml基本的spring boot 配置,主要用到的一个核心依赖是: 1 2 3 ...

Arthur_Holmes的博客 2181

保姆级教程:Synology NAS共享文件夹从创建到权限设置的完整流程

本文提供了一份详尽的Synology NAS共享文件夹创建与权限设置指南。重点讲解了如何将NAS接入企业AD域,并利用域管理员账户进行集中身份验证和权限管理。文章从基础概念、域环境配置、文件夹创建、精细化权限分配到客户端访问与维护,完整覆盖了构建安全高效企业级文件共享空间的全流程,旨在帮助管理员实现便捷的团队协作与数据安全管理。

u9v0w的博客 552

【QT】基于QSerialPort的跨平台串口通信实战指南

本文是一份基于Qt QSerialPort模块的跨平台串口通信实战指南。详细介绍了从硬件基础、QSerialPort核心类使用、参数配置、设备自动发现到数据异步读写和错误处理的完整流程,并通过构建一个功能齐全的串口调试助手实例,帮助开发者快速掌握在Windows、Linux和macOS系统下进行高效、稳定的串口应用开发。

a1b2c3d的博客 981

Springboot设计之properties配置文件properties、yml读取bean、map、list、map<String, Bean>属性

Springboot设计之properties配置文件属性读取

Ricardo.M.Yu的博客 1660

无符号整数、带符号整数溢出问题

让我们详细讲解一下带符号整数溢出和无符号整数溢出问题中,符号标志位 (SF)、零标志位 (ZF) 和进位标志位 (CF) 的行为方式

weixin_49342084的博客 2087

springboot-自定义properties文件

这里的关键主要是@PropertySource和@ConfigurationProperties(prefix = “user2”)和@Component。这样子就可以完成了,在迁移的过程中@PropertySource不支持yml语法,所以要变成properties,想要变成yml文件的小伙伴要注意哦。

学习的博客 637

我用 Python 监听了自己的键盘,生成击键热力图,看看每天到底在“摸鱼”还是“搬砖”?

数据采集(监听)、持久化(I/O)与可视化展示,必须是三个完全独立的模块,这符合单一职责原则。在多线程读写 Python 字典时,锁住的时间要尽可能短,防止 I/O 线程把高频的监听线程阻塞住。这类涉及底层的代码与“键盘记录木马”只有一线之隔。永远不要把击键记录通过网络上传,所有数据必须localhost消化。人脑对枯燥的 JSON 日志是不敏感的,但对颜色和空间极其敏感。这也是为什么 Prometheus + Grafana 是标配。使用ctypes。

BUG猿的博客 193

【unity小技巧】新输入系统InputSystem游戏运行中改键重新绑定控制按键(最全最完美解决方案)

在游戏开发中,控制输入是至关重要的一环。Unity的新输入系统(Input System)为开发者提供了强大的工具来管理和处理用户输入,不仅支持各种平台上的多种输入设备,还能轻松处理复杂的输入操作和映射。本文将深入探讨如何使用Unity的新输入系统重新绑定控制按键,为开发者提供一套全面且完善的解决方案。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 7357

SpringBoot(三):常用属性(Properties)汇总

Spring Boot(三):常用Properties汇总(已翻译) 作者:雨雾清影 出处:https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html 翻译:Google翻译 Spring Boot可以在application.properties/appli...

雨雾清影的个人博客 1041

由异常的测试眼图引发的深入思考

信号测试中出现“双眼皮”的眼图测试效果,可能的导致因素总结如下:PCB通道阻抗设计不匹配,负载端出现严重反射;发射端采用了不当的信号预处理;接收器均衡处理不当;通道串扰严重... 基于以上的假设,本文就逐一分析下这些因素到底是如何对正常的信号眼图造成影响的。

一只豌豆象的博客 3063

springboot读取自定义properties并注入到bean中

在使用springboot项目时,可使用@value的方式直接读取application.properties中的文件,但有时我们需要配置自定义的properties,下面方法将在springboot启动时利用fileinputstream读取properties文件中的内容,并注入到bean中,@Configuration注解会在springboot启动时执行一次,代码如下: package...

大明明 1万+

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

SpringBoot之Properties

30天学习SpringBoot

weixin_43997844的博客 1376

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

java之学习记录 9 - 1 - SpringBoot全局配置文件、自定义配置文件

全局配置文件能够对一些默认配置值进行修改。Spring Boot使用一个application.properties或者application.yaml的文件作为全局配置文件,该文件存放在src/main/resource目录或者类路径的/config,一般会选择resource目录。接下来,将针对这两种全局配置文件进行讲解 : Spring Boot配置文件的命名及其格式: application.properties application.yaml application.yml 1 a

dear_zx的博客 3280

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

springboot通过Properties类加载自定义配置文件

springboot加载配置文件有很多种方法,我主要说一下之前的通过Properties类加载自定义配置文件的 ,其他的加载配置文件的方式可以参考https://www.cnblogs.com/moonandstar08/p/7368292.html 自定义配置文件的文件目录resource目录下 加载类 public class CommonProperties2 { private...

weferxe的博客 2629

springboot 配置自定义配置文件,properties和yml文件,可用,没有location属性原因

因不想破坏application.yml的原生态,这里大都是框架系统相关的属性。自定义的一些属性就要单独存放一个文件了。 使用spring boot2.0的同学会发现ConfigurationProperties注解类的属性location已经取消了。 spring boot1.5.x之后版本取消了location。 参照了网上的几种方式,选了一种有效简单的方式,在此记录一下。 先添加po...

capricornce的博客 1311

SpringBoot自动装配封装自定义方法 + 通过Properties抽取公共属性配置

SpringBoot自动装配封装方法 + 通过Properties抽取公共属性配置,SpringBoot 和fastdfs-client 依赖冲突

weixin_44894196的博客 759

springBoot无法加载application.properties

问题 在测试类中,使用默认的application.yml可以读取到配置信息,切换为application.properties后无法读取,但是通过启动类又可以正常读取。 排查过程 1、怀疑自己的application.properties写法有问题,但是启动类能正常读取,排除。 2、怀疑测试类的注解存在问题,网上说的Junit5和4使用的注解不太一样,更换后并没有什么变化。(PS:新的@SpringBootTest已经集成了Junit5的@ExtendWith,根本不像网上说的需要添加)。 3、在指定自定

qq_40184195的博客 9950

springboot学习笔记:读取properties

跟随spring-boot-demo进行学习。 今天是第一个项目,读取properties。 项目的properties文件,是在src/main/java/resources 采用yml格式。 pom.xml 刚从学习项目中挪代码到项目中时,报了个groupId为空的错误。 pom.xml文件学习: pom.xml详解 后来我又从springboot挪了一个pom.xml过来,改吧改吧,解决了问题。分析了一下,问题应该出在parent那块。 下面是我用的pom.xml <?xml version="

peade的博客 445

springBoot 项目自定义命名application.properties配置文件名称

原创文章,转载请注明! springBoot项目自定义命名application.properties配置文件名称: 最近因项目原因,需要将springboot项目的properties文件改为自定义名称,在查看一些资料后最终解决,特记录一下!

wangyybx的博客 7646

【SpringBoot】【log】 自定义logback日志配置

SpringBoot官方建议使用logback-spring.xml作为logback框架的自定义日志配置文件,使用logback-spring.xml而不是logback.xml,因为带-spring后缀的配置文件可以使用使用Spring扩展profile支持,提供profile多环境日志输出得功能。将所有日志都存储在一个文件中文件大小也随着应用的运行越来越大并且不好排查问题,正确的做法应该是将 error日志和其他系统输出日志分开,并且不同级别的日志根据时间段进行记录存储。

m0_74825614的博客 1517

SpringBoot 配置文件 application.yml(application.properties) 配置大全

参考网址:https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html 可以在application.properties文件内部application.yml,文件内部或命令行开关中指定各种属性。本附录提供了常见Spring Boot属性的列表以及对使用它们的基础...

真是6的不行的博客 8014

Spring Boot 属性配置&自定义属性配置【测试通过】

在使用spring boot过程中,可以发现项目中只需要极少的配置就能完成相应的功能,这归功于spring boot中的模块化配置,在pom.xml中依赖的每个Starter都有默认配置,而这些默认配置足以满足正常的功能开发。 如果需要修改自定义修改默认配置,spring boot 提供了很简便的方法,只需要在application.properties 中添加修改相应的配置。(spring boot启动的时候会读取application.properties这份默认配置) 一、修改默认配置 ...

胡杰的专栏 1330

springboot 读取配置文件自定义属性值

1.在application.properties中 #短信发送配置 post.msg.pm-host=xxxxx post.msg.pm-cm-port=9080 post.msg.pm-ws-port=9070 post.msg.ac-name=xxx post.msg.ac-password=xxx 2.编写config配置类 pom.xml-->使用快速开发包 省略gett...

weixin_39209728的博客 1231
上一篇: SpringBoot 学习记录(七): Redis
下一篇: SpringBoot 学习记录(九): Email
小小小爬虫
博客等级 码龄10年 16粉丝 61原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值