【spring boot】使用@Value映射properties文件属性
描述
使用@Value映射properties文件属性到Java字段
重点
- 使用@PropertySource 注解指定*.properties文件位置;
- 使用@Value进行注入;
my.properties
book.author=ssslinppp
book.name=spring boot
Java类
package com.sssppp;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@PropertySource("classpath:my.properties")
public class Ch522 {
@Value("${book.author}")
private String bookAuthor;
@Value("${book.name}")
private String bookName;
@RequestMapping("/aa")
String index() {
return "book name is:" + bookName + " and book author is:" + bookAuthor;
}
}
【spring boot】使用@Value映射properties文件属性的更多相关文章
- spring boot 无法读取application.properties问题
spring boot 无法读取application.properties问题 https://bbs.csdn.net/topics/392374488 Spring Boot 之注解@Compo ...
- Spring Boot 的配置文件application.properties
Spring Boot 中的application.properties 是一个全局的配置文件,放在src/main/resources 目录下或者类路径的/config下. 作为全局配置文件的app ...
- Spring Boot加载application.properties配置文件顺序规则
SpringApplication会从以下路径加载所有的application.properties文件: 1.file:./config/(当前目录下的config文件夹) 2.file:./(当前 ...
- 一:Spring Boot 的配置文件 application.properties
Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...
- Spring boot 配置文件详解 (properties 和yml )
从其他框架来看 我们都有自己的配置文件, hibernate有hbm,mybatis 有properties, 同样, Spring boot 也有全局配置文件. Springboot使用一个全局的配 ...
- Spring Boot使用自定义的properties
spring boot使用application.properties默认了很多配置.但需要自己添加一些配置的时候,我们应该怎么做呢. 若继续在application.properties中添加 如: ...
- Spring boot 全局配置文件application.properties
#更改Tomcat端口号 server.port=8090 #修改进入DispatcherServlet的规则为:*.htmlserver.servlet-path=*.html#这里要注意高版本的s ...
- Spring boot 配置文件参数映射到配置类属性
[参考文章]:SpringBoot之@EnableConfigurationProperties分析 [参考文章]:在Spring Boot中使用 @ConfigurationProperties 注 ...
- Spring Boot 中配置文件application.properties使用
一.配置文档配置项的调用(application.properties可放在resources,或者resources下的config文件夹里) package com.my.study.contro ...
随机推荐
- git 应用
git - 简易指南 助你开始使用 git 的简易指南,木有高深内容,;). 安装 下载 git OSX 版 下载 git Windows 版 下载 git Linux 版 创建新仓库 创建新文件夹, ...
- window cmd-常用命令
1.常用命令 dir 文件列表 cd 改变目录md 创建目录 rd 删除目录 type 显示文件内容 fc 比较目录 attrib 修改文件属性 copy 复制文件 del 删除文件 ren 文件改名 ...
- NET Core MVC中创建PDF
使用Rotativa在ASP.NET Core MVC中创建PDF 在本文中,我们将学习如何使用Rotativa.AspNetCore工具从ASP.NET Core中的视图创建PDF.如果您使用ASP ...
- java-内部类访问特点-私有成员内部类-静态成员内部类-局部内部类访问局部变量
1.内部类访问特点: - 内部类可以直接访问外部类的成员,包括私有. - 外部类要访问内部类的成员,必须创建对象. - 外部类名.内部类名 对象名 = 外部类对象.内部类对象: - 例: class ...
- UE4 C++ Tips
篇写的是关于UE4的C++方面的小技巧: 1.在构造函数里 //构建组件 RootComponent = CreateDefaultSubobject<USceneComponent>(T ...
- AangularJS相关术语
1. 数据模型对象(model object)是指$scope对象.$scope对象又是一个简单的JavaScript对象,其中的属性可以被视图访问,也可以同控制器进行交互. 2. $scope ...
- 发布自己的npm包
如何发布自己写的npm包,这里有详细解释 : https://blog.csdn.net/u010130282/article/details/82629924 本文旨在解释遇到的问题: 1:需要设置 ...
- mongodb 通过mongodump来备份Sharded Cluste分片集群
1,mongodb所有组件官方文档地址:https://docs.mongodb.com/manual/reference/command/,所有的基础组件都在里面,包括备份恢复的mongodump. ...
- adx-desc-adtype统计
数据分析脚本: filepath="request.log.2017-12-01-15" File.open("#{filepath}").each do |l ...
- django之ORM专项训练之图书信息系统 了不起的双下方法实战 和 分组 聚合 Q, F查询,有約束和無約束
图书信息系统 双下方法的使用情况:要查确定的某一个对象他的属性值时, 首先获得具体对象的方法是 get() first() last() 获得具体对象之后,在找他的外键的属性 ge ...