SpringBoot---常规属性配置
1、概述
1.1、在Spring环境下,注入properties文件中的值,通过@PropertySource指明properties文件的位置,然后通过@Value注入值;
在SpringBoot环境下,我们只需要 在application.yml中定义属性,直接使用@Value注入即可;
package com.an.config; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource; /**
* @description:
* @author: anpeiyong
* @date: Created in 2019/11/19 14:56
* @since:
*/
@Configuration
@ComponentScan(value = "com.an")
@PropertySource(value = "classpath:test.properties")
public class ELConfig { }
package com.an.controller; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; /**
* @description:
* @author: anpeiyong
* @date: Created in 2019/11/19 15:34
* @since:
*/
@RestController
public class ELTestController { @Value(value = "${book.name}")
private String bookName; @Value(value = "${book.author}")
private String bookAuthor; @RequestMapping(value = "/eltest",method = RequestMethod.GET)
public String test(){
System.out.println("bookName:"+bookName+"+++++++++++"+"bookAuthor:"+bookAuthor);
return "hello";
} }
结果:
bookName:jackson+++++++++++bookAuthor:rose
SpringBoot---常规属性配置的更多相关文章
- SpringBoot项目属性配置-第二章
SpringBoot入门 1. 相信很多人选择Spring Boot主要是考虑到它既能兼顾Spring的强大功能,还能实现快速开发的便捷.我们在Spring Boot使用过程中,最直观的感受就是没有了 ...
- Springboot的常规属性配置和类型安全配置
1.类型常规配置: 通过在properties文件中注入键值对的方式,在java代码中通过@Value注解注入值 2.类型安全配置 将要注入的属性包装成一个类,给类加上注解:ConfigrationP ...
- SpringBoot常用属性配置
SpringBoot 2.x:https://github.com/spring-projects/spring-boot/blob/2.0.x/spring-boot-project/spring- ...
- spring boot学习(2) SpringBoot 项目属性配置
第一节:项目内置属性 application.properties配置整个项目的,相当于以前的web.xml: 注意到上一节的访问HelloWorld时,项目路径也没有加:直接是http://loca ...
- SpringBoot项目属性配置
如果使用IDEA创建Springboot项目,默认会在resource目录下创建application.properties文件,在SpringBoot项目中,也可以使用yml类型的配置文件代替pro ...
- springboot项目属性配置及注意事项
在idea编辑器建的springboot项目中的resources包下的application.properties这个就是配置文件. 另外配置文件的文件名还可以是application.yml,在r ...
- SpringBoot01 InteliJ IDEA安装、Maven配置、创建SpringBoot项目、属性配置、多环境配置
1 InteliJ IDEA 安装 下载地址:点击前往 注意:需要下载专业版本的,注册码在网上随便搜一个就行啦 2 MAVEN工具的安装 2.1 获取安装包 下载地址:点击前往 2.2 安装过程 到官 ...
- springBoot属性配置和使用
Spring Boot 属性配置和使用 1.添加属性文件 application.properties (名字固定) 2.访问端口生效 3.更多配置参考 # ===================== ...
- springboot快速入门(二)——项目属性配置(日志详解)
一.概述 application.properties就是springboot的属性配置文件 在使用spring boot过程中,可以发现项目中只需要极少的配置就能完成相应的功能,这归功于spring ...
- SpringBoot01 InteliJ IDEA安装、Maven配置、创建SpringBoot项目、yml属性配置、多环境配置、自定义properties配置
1 IntelliJ IDEA 安装 下载地址:点击前往 注意:需要下载专业版本的,注册码在网上随便搜一个就行啦 2 MAVEN工具的安装 2.1 获取安装包 下载地址:点击前往 2.2 安装过程 到 ...
随机推荐
- Oracle中start with...connect by/start with…connect by prior子句的用法
connect by 是结构化查询中用到的,其基本语法是:select … from tablenamestart with 条件1connect by 条件2where 条件3;例:select * ...
- 牛客多校第五场G
subsequence 1 只要处理长度等于t的. 转移方程没想出来QAQ $dp(i,j,0)$代表到$s[i]$为止有多少个前缀序列与$t[0\cdots j]$相同 所以有$dp(i,j,0)= ...
- algorithm_action
求矩阵Amk.Bkn的乘积 for(i=1;i<=m;i++) for(j=1;j<=n;j++) cij = 0 for(p=1;p<=k;p++) cij += aip*bpj
- JDBC常用接口、类介绍
JDBC常用接口.类介绍 JDBC提供对独立于数据库统一的API,用以执行SQL命令.API常用的类.接口如下: DriverManager 管理JDBC驱动的服务类,主要通过它获取Connectio ...
- 应用安全-Web安全-漏洞修复方案整理
通过HTTP头部字段防御措施整理 X-Frame-Options #反劫持 X-XSS-Protection #开启浏览器防XSS功能 Set X-Frame-Options CSP X-Conte ...
- 公司C++规范学习
目录 公司C++规范学习 语法部分 风格/约定 公司C++规范学习 语法部分 class和struct关键字的选择:class表示被封装的用户自定义类型,不公开定义非静态数据成员,struct表示数据 ...
- Map遍历方式
entrySet 推荐 最常用,性能很好 示例: for (Map.Entry<Integer, Integer> entry : map.entrySet()) { System.out ...
- JedisPool使用注意事项
转自:http://www.cnblogs.com/wangxin37/p/6397783.html JedisPool使用注意事项: 1.每次从pool获取资源后,一定要try-finally释放, ...
- 【xinsir】githook之precommit分享
钩子类型 使用node编写githook,以pre-commit为例: 1.在项目下配置自动生成pre-commit文件,一般可以在启动项目的脚本下添加: modifyPreCommit: funct ...
- wireshark自动化之tshark命令行
tshark是wireshark安装目录下命令行工具 使用tshark可以通过自动化方式调用wireshark tshark -a duration:30 抓包30秒-w cap.cap 保存为cap ...