springboot @PropertySource
@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的更多相关文章
- Spring Boot外部化配置实战解析
一.流程分析 1.1 入口程序 在 SpringApplication#run(String... args) 方法中,外部化配置关键流程分为以下四步 public ConfigurableAppli ...
- SpringBoot入门教程(十八)@value、@Import、@ImportResource、@PropertySource
Spring Boot提倡基于Java的配置.这两篇博文主要介绍springboot 一些常用的注解介绍 v@value 通过@Value可以将外部的值动态注入到Bean中. 添加applicatio ...
- Spring-boot中@ConfigurationProperties,@Value,@PropertySource
1.利用@ConfigurationProperties获取配置的值,@ConfigurationProperties是springboot提供的基于安全类型的配置放置. application.pr ...
- SpringBoot标签之@ConfigurationProperties、@PropertySource注解的使用
当获取主配置文件中属性值时,只需@ConfigurationProperties(prefix = "person")注解来修饰某类,其作用是告诉springBoot,此类中的属性 ...
- SpringBoot配置——@PropertySource、@ImportResource、@Bean
@PropertySource:加载指定的配置文件 package com.hoje.springboot.bean; import org.springframework.beans.factory ...
- 3springboot:springboot配置文件(配置文件、YAML、属性文件值注入<@Value、@ConfigurationProperties、@PropertySource,@ImportResource、@Bean>)
1.配置文件: springboot默认使用一个全局配置文件 配置文件名是固定的 配置文件有两种(开头均是application,主要是文件的后缀): ->application.prope ...
- SpringBoot 配置 @PropertySource、@ImportResource、@Bean
一.@PropertySource @PropertySource:加载指定的配置文件 @PropertySource(value = {"classpath:person.properti ...
- SpringBoot自定义注解@YamlPropertySource加载yml或者yaml文件(扩展了@PropertySource)
1:概述 SpringBoot的@PropertySource注解只支持加载 properties结尾的文件.当使用@ConfigurationProperties 注解配合@EnableConfig ...
- SpringBoot源码学习系列之@PropertySource不支持yaml读取原因
然后,为什么@PropertySource注解默认不支持?可以简单跟一下源码 @PropertySource源码: 根据注释,默认使用DefaultPropertySourceFactory类作为资源 ...
随机推荐
- 使用MonkeyTest对Android客户端进行压力测试
目录 monkey命令简介 monkey命令参数说明 自动化实例 如何通过日志定位问题 1.monkey命令简介 Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它 ...
- 测试笔试单选题(持续更新ing)
1.在GB/T17544中,软件包质量要求包括三部分,即产品描述要求._____.程 序和数据要求.( A ) A.用户文档要求 B.系统功能要求 C.设计要求说明 D.软件配置要求 2.软件的六大质 ...
- 适用于 Windows VM 的 Azure 示例基础结构演练
本文是更广泛系列的一部分,当你在 Azure 中构建应用程序基础结构时,这些系列向你提供设计注意事项和准则. 用户可以查看系列中的其他主题. 尽管用户可以在 Azure 中快速地构建出开发/测试环境, ...
- Qt与PyQT中设置ToolBar在AllowedArea的显示
因为个人对传统的软件GUI界面不是太喜欢,最近又在学习Qt和PyQt5,所以就有了设置ToolBar在窗口的不同地方的想法,经过浪里淘沙,最终在Qt官网里找到了,原来再添加toolBar的时候是由设置 ...
- web导出excel文件的几种方法
总的来说,两种方法:服务器端生成和浏览器端生成. 服务器端生成就是:根据用户请求,获取相应的数据,使用poi/jxl, jacob/jawin+excel,或是用数据拼html的table或是cvs纯 ...
- PowerShell发送邮件(587)
#定义邮件服务器 $smtpServer = "mail.xx.com" $smtpUser = "sender" $smtpPassword = " ...
- Spring hibernate 事务的流程
1 在业务方法开始之前 ①获取session ②把session和当前线程绑定,这样就可以在Dao中使用SessionFactory的getCurrentSession()方法来获取session了 ...
- [BZOJ 1135][POI2009]Lyz
[BZOJ 1135][POI2009]Lyz 题意 初始时滑冰俱乐部有 \(1\) 到 \(n\) 号的溜冰鞋各 \(k\) 双.已知 \(x\) 号脚的人可以穿 \(x\) 到 \(x+d\) 的 ...
- FZU Monthly-201901 获奖名单
FZU Monthly-201901 获奖名单 冠军: S031702338 郑学贵 一等奖: S031702524 罗继鸿 S031702647 黄海东 二等奖: S031702413 韩洪威 S0 ...
- 4、url控制系统
第1节:简单配置 参考代码: from django.conf.urls import url from . import views urlpatterns = [ url(r'^articles/ ...