springboot获取application.yml中的配置信息
HelloController.java
package com.springbootweb.demo.controller; import com.springbootweb.demo.entity.MyConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class HelloController { @Value("${myconfig}")
private String myconfig; @Value("${age}")
private String age; @Value("${content}")
private String content; //@RequestMapping("/hello")
@RequestMapping(value={"/hello","hi"})
public String say(){
String str="hello spring boot》》》》"+myconfig+";age:"+age;
str+="====";
str+=content;
return str;
} @Autowired
private MyConfigProperties cof; @RequestMapping("/conf")
public MyConfigProperties getConfig(){
return cof;
}
}
MyProperties.java
package com.springbootweb.demo.entity; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; @Component
@ConfigurationProperties(prefix = "myconfig1")
public class MyConfigProperties {
private String name;
private Integer age; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
}
}
DemoApplication
package com.springbootweb.demo; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Application.yml
server:
port: 8081
context-path: /t
myconfig: gys
age: 25
content: "myname:${myconfig},age:${age}"
myconfig1:
name: gysssssdddd
age: 35
springboot获取application.yml中的配置信息的更多相关文章
- SpringBoot 从application.yml中通过@Value读取不到属性值
package cn.exrick.xboot.mqtt; import org.eclipse.paho.client.mqttv3.*;import org.eclipse.paho.client ...
- springboot在application.yml中使用了context-path属性导致静态资源法加载,如不能引入vue.js,jquery.js,css等等
在springBoot配置中加入上下文路径 server.context-path=/csdn js,img等静态文件无法加载,出现404的问题 <script type="text/ ...
- springboot读取application.properties中自定义配置
假设在application-xxx.properties中配置 user.name=yuhk 一.在Controller中读取 @Value("{$user.name}") pr ...
- SpringBoot static修饰的字段/方法如何获取application.yml配置
SpringBoot的application.yml一种特殊的应用场景,一般我们获取application.yml的配置文件只要@Value就可以获取到值了,但是如果是static修饰的字段肯定就不能 ...
- SpringBoot读取yml中的配置,并分离配置文件
前言 在项目中经常遇到需要读取配置文件中的配置信息,这些配置信息之所以不写在代码中是因为实际项目发布或者部署之后会进行更改,而如果写在代码中编译之后没有办法进行修改. 之前使用的是properties ...
- SpringBoot学习(七)-->SpringBoot在web开发中的配置
SpringBoot在web开发中的配置 Web开发的自动配置类:在Maven Dependencies-->spring-boot-1.5.2.RELEASE.jar-->org.spr ...
- application.yml 常用基本配置
前言 在平时的项目开发中,自己对application.yml的配置的写法较为熟悉,现在自己就application.yml常用的配置进行总结如下: 1.Tomcat 配置 server: #设置请求 ...
- SpringBoot配置文件 application.properties,yaml配置
SpringBoot配置文件 application.properties,yaml配置 1.Spring Boot 的配置文件 application.properties 1.1 位置问题 1.2 ...
- Spring Boot项目application.yml文件数据库配置密码加密
在Spring boot开发中,需要在application.yml文件里配置数据库的连接信息,或者在启动时传入数据库密码,如果不加密,传明文,数据库就直接暴露了,相当于"裸奔"了 ...
随机推荐
- MySQL--查看内存信息
常见查看内存信息命令 ## 使用free -m命令查看 free -m ## 使用cat /proc/meminfo 查看 cat /proc/meminfo ## 使用dmidecode命令查看 d ...
- python查看及修改当前的工作路径
在pycharm中使用jupyter的时候,有时候需要查看当前的工作路径,然后需要修改当前的路径. 获取当前工作目录 os.getcwd() #用以获取当前的工作目录 改变当前工作目录 os.chdi ...
- Spring BeanFactory与FactoryBean的区别及其各自的详细介绍于用法
Spring BeanFactory与FactoryBean的区别及其各自的详细介绍于用法 1. BeanFactory BeanFactory,以Factory结尾,表示它是一个工厂类(接口),用于 ...
- 获取laravel项目的路径的内置帮助函数
app_path() app_path函数返回app目录的绝对路径: $path = app_path(); 你还可以使用app_path函数为相对于app目录的给定文件生成绝对路径: $path = ...
- LOJ 3055 「HNOI2019」JOJO—— kmp自动机+主席树
题目:https://loj.ac/problem/3055 先写了暴力.本来想的是 n<=300 的那个在树上暴力维护好整个字符串, x=1 的那个用主席树维护好字符串和 nxt 数组.但 x ...
- NET设计模式 第二部分 结构性模式(8):桥接模式(Bridge Pattern)
桥接模式(Bridge Pattern) ——.NET设计模式系列之九 Terrylee,2006年2月 概述 在软件系统中,某些类型由于自身的逻辑,它具有两个或多个维度的变化,那么如何应对这种“多维 ...
- Simple Logging Facade for Java 简单日志门面(Facade)
SLF4J是为各种 loging APIs提供一个简单统一的接口,从而使得最终用户能够在部署的时候配置自己希望的loging APIs实现.Logging API实现既可以选择直接实现SLF4J接口的 ...
- max_result_window
PUT http://192.168.1.12:9200/_settings { "index": { "max_result_window": "1 ...
- 在没有go-pear.bat的php中安装pear
因为需要安装phpunit,要先装pear,网上的教程大多数是以双击go-pear.bat开始,但是我安装的php文件夹里压根没有这个文件.经过几次搜索之后终于找到了办法.解决步骤如下:1.下载下面连 ...
- xe5 android 手机上使用sqlite [转]
在android手机上怎样使用sqlite数据库,这里用Navigator实现 增删改查. 1.新建firemonkey mobile application 2.选择blank applicatio ...