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

  1. //@Component:将组件注入到容器中
  2. @PropertySource(value = {"classpath:person.properties"})
  3. @Component
  4. @ConfigurationProperties(prefix = "person")
  5. public class Person {
  6. private String lastName;
  7. private Integer age;
  8. private Boolean boss;
  9. private Date date;
  10. private Map<String,Object> map;
  11. private List<Object> list;
  12. private Student student;
  13. public Student getStudent() {
  14. return student;
  15. }
  16. public void setStudent(Student student) {
  17. this.student = student;
  18. }

person.properties

  1. person.last-name=李四
  2. person.age=20
  3. person.date=2000/10/10
  4. person.boss=false
  5. person.map.k1=v1
  6. person.map.k2=v2
  7. person.list=a,b,c
  8. person.student.name=lisi
  9. person.student.age=13

测试

  1. @SpringBootTest
  2. class SpringBoot02ApplicationTests {
  3. @Autowired
  4. Person person;
  5. @Test
  6. void contextLoads() {
  7. System.out.println(person);
  8. }
  9. }

结果:

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. centos7下rsync+inotify脚本实现文件同步,.NET CORE客户端文件更新后自动重启服务

    源服务器IP:192.168.8.51 目标服务器IP:192.168.8.79 安装前源服务器及目标服务器均需关闭FIREWALLD\SELINUX防火墙 sestatus | grep statu ...

  2. CF1515H口胡

    居然一下就做出来了...不知道是不是对的/fad 考虑操作的本质,首先将所有元素插入线段树中. 来依次考虑每一种操作: 区间与 注意到这个操作类似将某些节点的右儿子合并到左儿子上,而一个节点最多被合并 ...

  3. CodeUp Problem D: More is better

    根据题目意思,输入的每一对A.B都是直接朋友,并且最后只会得到一个集合,该集合就是Mr Wang选择的男孩. 因此很容易写出代码,甚至不需要自己构建一个并查集,只需要使用C++的set模板,每次读入一 ...

  4. springcloud学习03-spring cloud eureka(上)

    对eureka一个大概介绍:https://blog.csdn.net/u010623927/article/details/88762525 这里面有个我做dubbo时的一个理解的错误:服务注册中不 ...

  5. CVE-2015-1427(Groovy 沙盒绕过 && 代码执行漏洞)

    1.vulhub环境搭建 https://blog.csdn.net/qq_36374896/article/details/84102101 2.启动docker环境 cd vulhub-maste ...

  6. Linux下swap(交换分区)的增删改

    swap介绍 Linux 的交换分区(swap),或者叫内存置换空间(swap space),是磁盘上的一块区域,可以是一个分区,也可以是一个文件,或者是他们的组合.交换分区的作用是,当系统物理内存吃 ...

  7. a{...}和 .box a{...}的渲染性能高低

    a{...}和 .box a{...}的渲染性能高低 .box a { ... } a{ ... } 因为对于CSS浏览器的渲染机制是选择器从右向左查询 .box a {...} 的渲染逻辑是:先找所 ...

  8. Python执行机制

    1.4 Python执行机制 Python中IDLE是其自带的集成开发工具(IDE:同时拥有编辑.编译.调试.运行等多种功能的集成工具),并且它也是Python自带的编译器和解释器. 1.4.1 Py ...

  9. 使用Web Deploy自动打包发布

    在内部测试阶段,经常改一点小东西需要更新给测试继续测试.然后就需要频繁的找到对应更改的视图/JS文件,或者是编译的dll文件,再打开测试服务器找到对应站点替换进去,整套流程下来就非常的繁琐费时. 使用 ...

  10. 使用docker配置laravel5.5环境

    简介 简述一下我用docker来配置laravel环境 软件镜像 php:7.2-rc-fpm-alpine mysql:5.6 nginx:1.12.2-alpine 配置环境 Ubuntu:16. ...