描述

使用@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. 田螺便利店——联想笔记本进入不了BIOS的解决方法

    当计算机遇到问题时,很多情况下需要进入BIOS进行解决.但很多新出的联想笔记本电脑在开机时,无论怎么疯狂的按F2,Fn+F2,F12或者Del,都无法进入BIOS,十分气人.       这种现象出现 ...

  2. HPU第四次积分赛-L:A Winged Steed(完全背包)

    A Winged Steed 描述 有n种千里马,每一种都有若干匹,第i种马的颜值ai​,价格di​.现有m个牧马人要去挑选千里马,每一位牧马人对马的颜值都有要求:{所选马的颜值总和} ⩾Ai​.现在 ...

  3. 【HDOJ1811】【并查集预处理+拓扑排序】

    http://acm.hdu.edu.cn/showproblem.php?pid=1811 Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) ...

  4. UVALive-6540 Fibonacci Tree

    #include<bits/stdc++.h> using namespace std; int n,m; struct edge { int x; int y; int len; }ed ...

  5. hdu1695 GCD 容斥原理

    Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) ...

  6. linux freopen函数

    编程之路刚刚开始,错误难免,希望大家能够指出. 有些需求需要我们不断的输入数据很庞大,如果我们安装常规方法不断地在终端输入值很麻烦(前提是输入的数据是固定的,并不会随程序的运行而改变),这个时候我们就 ...

  7. itcast-spring

    黑马2014  spring后期 ssh整合后期  讲解不清楚 源码讲解太多   spring重新开始  itcast2016版本 介绍 Spring搭建 约束引入注意事项 导入至eclipse:wi ...

  8. Centos7 安装redis及其入门使用

    wget -c http://download.redis.io/releases/redis-3.2.9.tar.gz #下载源码 tar -xvf redis-3.2.9.tar.gz #解压 c ...

  9. 原生js实现ajax用于简单的签到或登录

    <script> function createStandardXHR() {     try {         return new window.XMLHttpRequest(); ...

  10. 10 Rules of Highly Successful Project Management

    I commited the information below to report PDU of PMI. ^_^. In this paper, the author introduces his ...