Spring Boot基础学习04 – Spring Boot加载自定义配置文件

  • Post author:
  • Post category:其他




一、使用@PropertySource加载自定义配置文件



(一)创建Spring Boot Web项目ConfigDemo01

  • 设置项目元数据

    在这里插入图片描述
  • 添加项目依赖

    在这里插入图片描述
  • 设置项目名称与保存位置

    在这里插入图片描述
  • 完成项目初始化工作

    在这里插入图片描述



(二)创建自定义配置文件

  • 在resources下创建myconfig.properties文件

    在这里插入图片描述



(三)创建自定义配置类

  • 在net.lbj.lesson04包里创建子包config在创建配置类StudentConfig
package net.lbj.lesson04.config;

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

/**
 *学生配置类
 * 20210507
 */
@Component



版权声明:本文为lbj5063原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。