描述

使用@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. sudo: sorry, you must have a tty to run sudo

    使用ssh进行无密访问,并发送执行命令的时候遇到了如题的错误 执行命令ssh user@host "sudo rm /data/test,txt" sudo: sorry, you ...

  2. 【HDOJ1598】【枚举+最小生成树】

    http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000/1000 ...

  3. 免费获取pptv会员

    打开上面的网址!领取会员!http://vip.pptv.com/activity/2016/licaitong http://vip.pptv.com/activity/2016/caifutong ...

  4. {python}完成完整的温度转换程序 猜数字游戏(猜价格,猜年龄等) 解析身份证号、学号不同片段的含义

    完成完整的温度转换程序 while True: a = int(input("如果是华氏转摄氏,请按1\n,如果是摄氏转华氏,请按2\n")) if a==1: h = float ...

  5. Commons工具包的使用

    使用步骤: 1.Java  Project下新建Folder文件夹,命名lib 2.lib文件夹下把Commons-io-2.4jar包复制进去 3.右键Commons-io-2.4jar包,点击Bu ...

  6. 改变codeblocks里面各种注释的颜色。

    ->Setting->Editor->Syntax highlighting->“Comment(normal)” /* 改变块注释颜色 */"Comment lin ...

  7. 数学 它的内容,方法和意义 第一卷 (A. D. 亚历山大洛夫 著)

    第一章 数学概观 (已看) 1. 数学的特点 2. 算术 3. 几何 4. 算术和几何 5. 初等数学时代 6. 变量的数学 7. 现代数学 8. 数学的本质 9. 数学发展的规律性 第二章 数学分析 ...

  8. c#实现RGB字节数组生成图片

    我是要用c#来实现,现在已经知道了rgb数组,那么如何快速生成一张图片呢? 其实这个话题并不局限于是rgb字节数组的顺序,只要你能对于上表示红.绿.蓝的值,就可以生成图片.知道了原理,做什么都简单了. ...

  9. 查看JVM运行时参数

    1.查看JVM运行时参数 -XX:+PrintFlagsInitial -XX:PrintFlagsFinal -XX:+UnlockExperimentalVMOptions 解锁实验参数 -XX: ...

  10. 深入理解ASP.NET MVC(3)

    系列目录 URL是如何通过路由表生成的(outbound) 通常我们被推荐在view设计时使用Html.ActionLink(…)产生链接,这样做的优势就是,url可以根据路由表生成.路由机制的另一个 ...