@PropertySource:加载自己手动编写的资源文件
有关@ConfigurationProperties注解的作用请访问Spring Boot-@Value获取值和@ConfigurationProperties获取值的比较

//@Component:将组件注入到容器中
@PropertySource(value = {"classpath:person.properties"})
@Component
@ConfigurationProperties(prefix = "person")
public class Person { private String lastName;
private Integer age;
private Boolean boss;
private Date date; private Map<String,Object> map; private List<Object> list; private Student student; public Student getStudent() {
return student;
} public void setStudent(Student student) {
this.student = student;
}

person.properties

person.last-name=李四
person.age=20
person.date=2000/10/10
person.boss=false
person.map.k1=v1
person.map.k2=v2
person.list=a,b,c
person.student.name=lisi
person.student.age=13

测试

@SpringBootTest
class SpringBoot02ApplicationTests { @Autowired
Person person; @Test
void contextLoads() {
System.out.println(person);
} }

结果:

Spring Boot-@PropertySource注解的更多相关文章

  1. Spring Boot 常用注解汇总

    一.启动注解 @SpringBootApplication @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documen ...

  2. Spring boot 基于注解方式配置datasource

    Spring boot 基于注解方式配置datasource 编辑 ​ Xml配置 我们先来回顾下,使用xml配置数据源. 步骤: 先加载数据库相关配置文件; 配置数据源; 配置sqlSessionF ...

  3. Spring Boot常用注解总结

    Spring Boot常用注解总结 @RestController和@RequestMapping注解 @RestController注解,它继承自@Controller注解.4.0之前的版本,Spr ...

  4. 3个Spring Boot核心注解,你知道几个?

    Spring Boot 核心注解讲解 Spring Boot 最大的特点是无需 XML 配置文件,能自动扫描包路径装载并注入对象,并能做到根据 classpath 下的 jar 包自动配置. 所以 S ...

  5. Spring Boot@Component注解下的类无法@Autowired的问题

    title: Spring Boot@Component注解下的类无法@Autowired的问题 date: 2019-06-26 08:30:03 categories: Spring Boot t ...

  6. 【SpringBoot】15. Spring Boot核心注解

    Spring Boot核心注解 1 @SpringBootApplication 代表是Spring Boot启动的类 2 @SpringBootConfiguration 通过bean对象来获取配置 ...

  7. spring boot纯注解开发模板

    简介 spring boot纯注解开发模板 创建项目 pom.xml导入所需依赖 点击查看源码 <dependencies> <dependency> <groupId& ...

  8. Spring Boot中注解@ConfigurationProperties

    在Spring Boot中注解@ConfigurationProperties有三种使用场景,而通常情况下我们使用的最多的只是其中的一种场景.本篇文章带大家了解一下三种场景的使用情况. 场景一 使用@ ...

  9. Spring boot @PropertySource, @ImportResource, @Bean

    @PropertySource:加载指定的配置文件 /** * 将配置文件中配置的每一个属性的值,映射到这个组件中 * @ConfigurationProperties:告诉SpringBoot将本类 ...

  10. Spring Boot 核心注解与配置文件

    @SpringBootApplication注解 Spring Boot项目有一个入口类 (*Application) 在这个类中有一个main 方法,是运行该项目的切入点.而@SpringBootA ...

随机推荐

  1. VMware15安装 CentOS7 步骤

  2. Docker——dockerfile

    dockerFile介绍 dockerFile是用来构建docker镜像的文件!命令参数脚本! 步骤: 编写dockerFile文件 docker build构建成为一个镜像 docker run运行 ...

  3. 随手用Java写的bilibili缓存视频转换器(合成分离的视频和音频)

    使用java随手写成,有需要可以自行修改. 项目使用到了fastjson,可以自行替换成其他json解析工具. 写这个的原因是因为下载到的其他工具弄出来的视频标题过长(应该取entry.json中的s ...

  4. Apache HTTPD 未知后缀解析漏洞

    环境搭建 https://blog.csdn.net/qq_36374896/article/details/84102101 该环境版本: PHP 7.x 最新版 Apache HTTPD 2.4. ...

  5. JavaScript day04 函数

    函数 函数讲解 函数是什么? 函数其实就抽取写好的js代码 作为一个通用的代码块 (封装) 作用: 减少代码冗余 (过多) 方便调用 (提供效率 提高代码的可读性) 便于维护 (二次修改) js有哪些 ...

  6. 为什么不建议使用统配符初始化 css 样式

    为什么不建议使用统配符初始化 css 样式 * { padding:0; margin:0; } 采用这样的写法好处是写起来很简单,但是通配符,需要把所有的标签都遍历一遍,当网站较大时,样式比较多,这 ...

  7. Java时间处理类LocalDate和LocalDateTime常用方法

    Java时间处理类LocalDate和LocalDateTime常用方法 https://blog.csdn.net/weixin_42579074/article/details/93721757

  8. 如何通过sql语句完成分页?

    oracle select rownum,bookId from [rownum是伪列名,bookId是列名] (select rownum row_id,bookId from xiaoWJ_boo ...

  9. 为什么 wait 和 notify 方法要在同步块中调用?

    Java API 强制要求这样做,如果你不这么做,你的代码会抛出 IllegalMonitorStateException 异常.还有一个原因是为了避免 wait 和 notify 之间产生竞态条件.

  10. nginx搭建简单直播服务器

    1.下载模块(nginx-rtmp-module) 1 cd /data/nginx 2 yum install git3 git clone https://github.com/arut/ngin ...