SpringBoot | 读取配置文件信息
server.port=8081 #修改端口号
server.servlet.context-path= /SpringBoot #修改URL
#自定义配置
tz.name = xiaoming
tz.phone = 136****78789
tz.age = 18
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component; @Component
@PropertySource("classpath:application.properties") //Spring boot1.5.1之后,就废除了location参数,转而使用@PropertySource指定配置文件路径,不使用@ConfigurationProperties
public class TzInformation {
@Value("${tz.name}")
private String name;
@Value("${tz.phone}")
private String phone;
@Value("${tz.age}")
private String age; public String getName() {
return name;
} public String getPhone() {
return phone;
} public String getAge() {
return age;
} @Override
public String toString() {
return "TzInformation{" +
"name='" + name + '\'' +
", phone='" + phone + '\'' +
", age='" + age + '\'' +
'}';
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; @RestController
public class helloController {
@Autowired
TzInformation tzInformation;
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public String say() {
return "Hello SpringBoot! ";
} @RequestMapping(value = "/tz",method = RequestMethod.GET)
public String information(){
return tzInformation.toString();
}
}
SpringBoot | 读取配置文件信息的更多相关文章
- springboot读取配置文件中的信息
在一个项目中,我们有时候会把一些配置信息写入到一个配置文件中,在java代码中读取配置文件的信息.在此记录下读取属性文件中的内容. 在springboot项目中,springboot的配置文件可以使用 ...
- Asp.net Core 和类库读取配置文件信息
Asp.net Core 和类库读取配置文件信息 看干货请移步至.net core 读取配置文件公共类 首先开一个脑洞,Asp.net core 被使用这么长时间了,但是关于配置文件(json)的读取 ...
- SpringBoot读取配置文件源码探究
1. SpringBoot读取配置文件源码探究 1.1. 概览 springboot的源码是再原来的Spring源码上又包了一层,看过spring源码都知道,当我们从入口debug进去的时候,原来的S ...
- SpringBoot 读取配置文件的值 赋给静态变量
需求:写了一个工具类,但是工具类中的一些变量需要放到配置文件中,而这个工具类中的变量与方法都是静态的,这个时候我需要一个办法将配置文件中的相关配置读取过来赋值给这些静态变量.找了一些文章,试了一些方法 ...
- springboot读取配置信息、环境变量
2.读取配置文件 2.1 读取核心配置文件 核心配置文件是指在resources根目录下的application.properties或application.yml配置文件,读取这两个配置文件的方法 ...
- Springboot读取配置文件的两种方法
第一种: application.yml配置中的参数: zip: Hello Springboot 方法读取: @RestController public class ControllerTest ...
- springboot 读取配置文件
读取配置文件 在以前的项目中我们主要在 XML 文件中进行框架配置,业务的相关配置会放在属性文件中,然后通过一个属性读取的工具类来读取配置信息. 在 Spring Boot 中我们不再需要使用这种方式 ...
- SpringBoot读取配置文件的内容
1.@Value读取 在springboot项目中,如果要读取配置文件application.properties或application.yml文件的内容,可以使用自带的注解@Value.以prop ...
- ConfigParser_读取配置文件信息
ConfigParse简介 ConfigParser 在python中是用来解析配置文件的内置模块,直接导入使用 import configparser 使用该模块可以对配置文件进行增.读.改.删操作 ...
随机推荐
- CA与数字证书的自结
1.CA CA(Certificate Authority)是数字证书认证中心的简称,是指发放数字证书.管理数字证书.废除数字证书的权威机构. 2.数字证书 如果向CA申请数字证书的单位为A.则他申请 ...
- Cannot instantiate the type AppiumDriver,AppiumDriver升级引发的问题
转自:http://blog.csdn.net/zhubaitian/article/details/39717889 1. 问题描述和起因 在使用Appium1.7.0及其以下版本的时候,我们可以直 ...
- STL review:vector & string & map & struct
I.vector 1.头文件:#include<vector> //容器vector是一个能实现随机存取.插入删除的动态数组,还可以当栈使. ...
- button在firefox 和 ie 下的问题
最近做了一个关于数据库管理的项目,因为不用考虑ie9以下的兼容性,所以一股脑的写完啦,到测试的时候发现了一个bug IE和火狐下有个模块关闭按钮的hover没有反应,ie不行就算了,火狐怎么也不行?我 ...
- 基于Vuejs的搜索匹配功能
最近一直在看vue,查了很多资料,看了很多文档和博客,大概半知半解了,然后利用所理解的知识写了一个简单的搜索匹配功能. 大概长这个样子: <!DOCTYPE html> <htm ...
- hdu2544 迪杰斯特拉题目优化
点击打开题目链接 迪杰斯特拉的用法不多讲,详见 点击打开链接 . 下面两个代码: 这个是用邻接矩阵存图的迪杰斯特拉. #include<stdio.h> int main() { int ...
- codeforces 690C3 C3. Brain Network (hard)(lca)
题目链接: C3. Brain Network (hard) time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- 「HNSDFZ暑期集训 测试1」「LuoguT36485」 括号(贪心
Description 给定一个由左括号'('和右括号')'组成的字符串s,其中第i个括号的权值为ai. 我们定义一个括号序列t为合法括号序列,当且仅当满足下列条件之一: 1.t为空串 2.t=(A) ...
- The Castle
链接 分析:先暴力求出联通块数和最大联通块包含多少,接着对于每个位置判断去掉其上下左右的四个位置的墙之后的最大联通块数,并且记得先选最西,然后选最南的顺序了来输出 /* PROB:castle ID: ...
- 【USACO2017JAN】 Promotion Counting
[题目链接] 点击打开链接 [算法] 离散化 + dfs + 树状数组 [代码] #include<bits/stdc++.h> using namespace std; #define ...