Springboot3.5.x版本从环境变量加载属性

前言

Springboot3.5.x版本已经发布了,伴随着新属性的发型,能从环境变量加载属性

从环境变量加载属性

Springboot3.5.x版本之前,已经可以从环境变量加载单个属性,但现在,Spring Boot 3.5.x版本开始,可以从单个环境变量加载多个属性

备注: 本文使用的是window配置变量 1、进入到环境变量

2、然后在全局环境下配置

3、创建一个springboot3.5.x版本

4、配置环境变量

arduino 复制代码
spring.config.import=env:USER_CONFIGURATION

5、写一个获取配置变量接口

kotlin 复制代码
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class IndexController {


    @Value("${user.age}")
    private Integer age;

    @GetMapping("/hello")
    public Integer hello() {
        return age;
    }
}

6、启动程序

7、访问

http://localhost:8085/hello

结果如下图

备注: 如果idea已经启动了,而后配置的环境变量,要重启idea

总结

Springboot3.5.x版本已经发布了,而且伴随着一些新属性使用,可以在开发中使用,方便开发,不过看个人技术选型。Springboot4.0.0跟快也要发版

相关推荐
咖啡八杯3 小时前
GoF设计模式——策略模式
java·后端·spring·设计模式
lizhongxuan4 小时前
AI Agent 上下文压缩利器 Headroom
后端
Csvn6 小时前
SSH 远程管理与安全加固 — 运维的守门之道
后端
IT_陈寒7 小时前
Python搞不定字符串编码?这破玩意坑我两小时!
前端·人工智能·后端
菜鸟谢8 小时前
Rust 智能指针完整详解
后端
java小白小8 小时前
SpringBoot(01): 初识SpringBoot,从Spring的痛点说起
spring boot
菜鸟谢8 小时前
Rust 函数完整知识点详解
后端
爱勇宝8 小时前
淡泊名利之前,先承认我们都很焦虑
前端·后端·程序员
菜鸟谢8 小时前
Rust 闭包(Closure)完整详解
后端
ServBay8 小时前
如何利用本地技术栈构建 0 成本 AI SaaS 雏形
后端·aigc·ai编程