@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. 字节顺序标记BOM

    最近,从numbers导出的csv文件,导入excel后,出现中文乱码问题.网上查询后,发现是numbers导出的csv默认是utf-8无BOM的,使用sublimText3打开,另存为utf-8wi ...

  2. SQLSERVER 分区表实战

    背景:对NEWISS数据库创建分区表T_SALES的SQL.按照日期来进行分区步骤:1:创建文件组2:创建数据文件3:创建分区函数4:创建分区方案5:创建表及聚集索引6:导入测试数据(此处略),并查询 ...

  3. Oracle 密码失灵

    java.sql.SQLException: ORA-28001: 密碼已經屆滿 at oracle.jdbc.driver.DatabaseError.throwSqlException(Datab ...

  4. mysql processlist 线程状态

        Analyzing 线程是对MyISAM 表的统计信息做分析(例如, ANALYZE TABLE ).   checking permissions 线程是检查服务器是否具有所需的权限来执行该 ...

  5. 转:C# lock用法

    lock 的目的很明确:就是不想让别人使用这段代码,体现在多线程情况下,只允许当前线程执行该代码区域,其他线程等待直到该线程执行结束:这样可以多线程避免同时使用某一方法造成数据混乱. 一般定义如下: ...

  6. python提示警告InsecureRequestWarning

    在Python3中使用以下代码报错: import requests response = requests.get(url='', verify=False) 错误代码如下: InsecureReq ...

  7. Linux平台安装Oracle11gR2数据库

    1. 数据库安装先决条件 1.1 认证的操作系统检查确认 o RHEL4,OEL4 - update 7 or greater o RHEL5,OEL5 - 5.2 or greater o RHEL ...

  8. 关于JRebel启动tomcat访问上次工程的index.jsp

    检查了一下,原来我把上次配置文件包括JRebel配置文件一起复制过来,用JRebel启动时tomcat访问JRebel配置文件的目录下 这个是我上次文件的路径,把JRebel配置文件删除了,然后 di ...

  9. 【转】 python中 * 的用法

    转自:https://www.cnblogs.com/jony7/p/8035376.html 1.表示乘号 2.表示倍数,例如: def T(msg,time=1):    print((msg+' ...

  10. scapy学习笔记(4)简单的sniffing 嗅探

    转载请注明:@小五义:http://www.cnblogs/xiaowuyi 利用sniff命令进行简单的嗅探,可以抓到一些简单的包.当不指定接口时,将对每一个接口进行嗅探,当指定接口时,仅对该接口进 ...