@ConfigurationProperties(prefix="person") 默认加载全局配置文件 application.properties或application.yml

application.properties文件中有字段 persion.first-name

@PropertySource 加载指定路径的配置文件信息

application.properties同级目录有person.properties first-name 如读取person.properties需要加@PropertySource  注解并指定路径@PropertySource(value = { "classpath:person.properties" })

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component; @Component
@PropertySource(value = { "classpath:person.properties" })
@ConfigurationProperties(prefix="person")
public class Person { private String firstName; }

@ImportResource:导入Spring的配置文件,让配置文件里面的内容生效 (@importResource标注在一个配置类上)

@ImportResource(location={"classpath:xxx.xml"})
导入spring的配置文件让其生效

@Configuration:指明当前类是一个配置类;就是来替代之前的Spring配置文件;在配置文件中用<bean><bean/>标签添加组件

springboot推荐给容器中添加组件的方式:推荐使用全注解方式

1、配置类  相当于spring配置文件

2.使用@Bean 给容器添加组件

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; @Configuration
public class MyAppConfig { //将方法的返回值添加到容器中;容器中这个组件默认的id就是方法名
@Bean
public HelloService helloService(){
return new HelloService();
}
}

springboot @PropertySource的更多相关文章

  1. Spring Boot外部化配置实战解析

    一.流程分析 1.1 入口程序 在 SpringApplication#run(String... args) 方法中,外部化配置关键流程分为以下四步 public ConfigurableAppli ...

  2. SpringBoot入门教程(十八)@value、@Import、@ImportResource、@PropertySource

    Spring Boot提倡基于Java的配置.这两篇博文主要介绍springboot 一些常用的注解介绍 v@value 通过@Value可以将外部的值动态注入到Bean中. 添加applicatio ...

  3. Spring-boot中@ConfigurationProperties,@Value,@PropertySource

    1.利用@ConfigurationProperties获取配置的值,@ConfigurationProperties是springboot提供的基于安全类型的配置放置. application.pr ...

  4. SpringBoot标签之@ConfigurationProperties、@PropertySource注解的使用

    当获取主配置文件中属性值时,只需@ConfigurationProperties(prefix = "person")注解来修饰某类,其作用是告诉springBoot,此类中的属性 ...

  5. SpringBoot配置——@PropertySource、@ImportResource、@Bean

    @PropertySource:加载指定的配置文件 package com.hoje.springboot.bean; import org.springframework.beans.factory ...

  6. 3springboot:springboot配置文件(配置文件、YAML、属性文件值注入<@Value、@ConfigurationProperties、@PropertySource,@ImportResource、@Bean>)

    1.配置文件: springboot默认使用一个全局配置文件 配置文件名是固定的   配置文件有两种(开头均是application,主要是文件的后缀): ->application.prope ...

  7. SpringBoot 配置 @PropertySource、@ImportResource、@Bean

    一.@PropertySource @PropertySource:加载指定的配置文件 @PropertySource(value = {"classpath:person.properti ...

  8. SpringBoot自定义注解@YamlPropertySource加载yml或者yaml文件(扩展了@PropertySource)

    1:概述 SpringBoot的@PropertySource注解只支持加载 properties结尾的文件.当使用@ConfigurationProperties 注解配合@EnableConfig ...

  9. SpringBoot源码学习系列之@PropertySource不支持yaml读取原因

    然后,为什么@PropertySource注解默认不支持?可以简单跟一下源码 @PropertySource源码: 根据注释,默认使用DefaultPropertySourceFactory类作为资源 ...

随机推荐

  1. Hibernate 注释用法

    注释 到现在为止,你已经看到 Hibernate 如何使用 XML 映射文件来完成从 POJO 到数据库表的数据转换的,反之亦然.Hibernate 注释是无需使用 XML 文件来定义映射的最新方法. ...

  2. Oracle 当数据库的表没有drop操作就可以通过如下方式恢复表数据

    --执行下列语句可查询出相关时间点 select * from sys.smon_scn_time order by time_dp desc; --执行下列语句可将某个时间点的数据恢复 insert ...

  3. NaviCat SqlServer Windows 10 Update 1803 IM004 - Driver's SQLAllocHandle on SQL_HANDLE_ENV failed

    安装Windows 10 Update 1803后,Navicat连接SqlServer出现以下错误: IM004 - Driver's SQLAllocHandle on SQL_HANDLE_EN ...

  4. MariaDB实现主从配置及读写分离(一)

    一.主从复制方案 1.  在两台CentOS7虚拟机上分别部署MariaDB, 主数据库服务器IP为192.168.17.235, 从服务器IP为192.168.17.238. 从服务器通过调取主服务 ...

  5. Character Sets: Migrating to utf8mb4 with pt_online_schema_change

    David Berube  | June 12, 2018 |  Posted In: MySQL Modern applications often feature the use of data ...

  6. Python处理Windows事件日志(json)

    通过NXlog将Windows事件日志保存为json格式文件,然后在Python中使用json.loads()进行处理. NXlog在将Windows事件日志保存为json格式文件,文件中带入了BOM ...

  7. Linux运维之——每日小技巧,谈进程与线程的区别

    线程是进程中执行运算的最小单位,是进程中的一个实体,是被系统独立调度和分派的基本单位,线程自己不拥有系统资源,只拥有一点在运行中必不可少的资源,但它可与同属一个进程的其它线程共享进程所拥有的全部资源. ...

  8. 【11】python 递归,深度优先搜索与广度优先搜索算法模拟实现

    一.递归原理小案例分析 (1)# 概述 递归:即一个函数调用了自身,即实现了递归 凡是循环能做到的事,递归一般都能做到! (2)# 写递归的过程 1.写出临界条件 2.找出这一次和上一次关系 3.假设 ...

  9. leetcode 1. Two Sum [java]

    注意点: HashMap<Integer, Integer> return new int[]{}; 3 2 4 target:6 return null; public int[] tw ...

  10. PyQt5--ShowWindowCenter

    # -*- coding:utf-8 -*- ''' Created on Sep 13, 2018 @author: SaShuangYiBing ''' import sys from PyQt5 ...