描述

使用@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文件属性的更多相关文章

  1. spring boot 无法读取application.properties问题

    spring boot 无法读取application.properties问题 https://bbs.csdn.net/topics/392374488 Spring Boot 之注解@Compo ...

  2. Spring Boot 的配置文件application.properties

    Spring Boot 中的application.properties 是一个全局的配置文件,放在src/main/resources 目录下或者类路径的/config下. 作为全局配置文件的app ...

  3. Spring Boot加载application.properties配置文件顺序规则

    SpringApplication会从以下路径加载所有的application.properties文件: 1.file:./config/(当前目录下的config文件夹) 2.file:./(当前 ...

  4. 一:Spring Boot 的配置文件 application.properties

    Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...

  5. Spring boot 配置文件详解 (properties 和yml )

    从其他框架来看 我们都有自己的配置文件, hibernate有hbm,mybatis 有properties, 同样, Spring boot 也有全局配置文件. Springboot使用一个全局的配 ...

  6. Spring Boot使用自定义的properties

    spring boot使用application.properties默认了很多配置.但需要自己添加一些配置的时候,我们应该怎么做呢. 若继续在application.properties中添加 如: ...

  7. Spring boot 全局配置文件application.properties

    #更改Tomcat端口号 server.port=8090 #修改进入DispatcherServlet的规则为:*.htmlserver.servlet-path=*.html#这里要注意高版本的s ...

  8. Spring boot 配置文件参数映射到配置类属性

    [参考文章]:SpringBoot之@EnableConfigurationProperties分析 [参考文章]:在Spring Boot中使用 @ConfigurationProperties 注 ...

  9. Spring Boot 中配置文件application.properties使用

    一.配置文档配置项的调用(application.properties可放在resources,或者resources下的config文件夹里) package com.my.study.contro ...

随机推荐

  1. HDU 1171 Big Event in HDU dp背包

    Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...

  2. java-Random类

    1.Random类的概述和方法使用 * A:Random类的概述 * 此类用于产生随机数 * 如果用相同的种子创建两个 Random 实例,则对每个实例进行相同的方法调用序列,它们将生成并返回相同的数 ...

  3. Thymeleaf基本用法

    1.Thymeleaf简介 官方网站:https://www.thymeleaf.org/index.html Thymeleaf是用来开发Web和独立环境项目的现代服务器端Java模板引擎. 2.特 ...

  4. PS学习之合成特效:被风沙侵蚀的动物们

    素材 大象 尘埃 裂纹 沙子 土地 正式操作: 打开PS 新建一个文件 选国际标准纸张  给分辨率为72(分辨率越大越占内存) 然后确定  将图片旋转90度(图像——旋转——(顺/逆)90度) 下面选 ...

  5. 使用JQuery反向选择checkbox

    HTML代码: <input id="haspda" type="checkbox" name="haspda" value=&quo ...

  6. Sencha Touch app example -- oreilly app 分析

    from: 2013/8/30的笔记 使用development.js 读取 app.json 配置文件 app.json 配置了app.js文件 app.js lauch function ,首先用 ...

  7. css中的margin(外边框)、border(边框)、padding(填充)的区别

    Margin(外边距) - 清除边框外的区域,外边距是透明的. Border(边框) - 围绕在内边距和内容外的边框. Padding(内边距) - 清除内容周围的区域,内边距是透明的. Conten ...

  8. LeetCode – Most Common Word

    Given a paragraph and a list of banned words, return the most frequent word that is not in the list ...

  9. Gravitational Teleport docker-compose组件独立部署运行

    Gravitational Teleport 可以作为堡垒机进行使用,上次写过一个all in one 的,这次参考官方 的配置运行一个proxy node auth 分离的应用 备注: 基于dock ...

  10. ViewBag & ViewData

    ViewBag 和ViewData 是ASP.NET MVC 开发当中大家使用很多的传递数据的方法 VB可以称为VD的一块语法糖, VB是使用C# 4.0动态特征, 使得VD也具有动态特性. 下面就是 ...