Spring PropertySource,获取指定application.properties文件
@PropertySource注解的使用
- @PropeertySource,指定加载配置文件
- 配置文件映射到实体类
- 使用@Value映射到具体的java属性
CustomConfig.java
package net.cybclass.sp.aop; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource; @Configuration
@PropertySource(value = "classpath:config.properties")
public class CustomConfig {
@Value("${server.host}")
private String host;
@Value("${server.port}")
private int port; public String getHost() {
return host;
} public void setHost(String host) {
this.host = host;
} public int getPort() {
return port;
} public void setPort(int port) {
this.port = port;
} @Override
public String toString() {
return "CustomConfig{" +
"host='" + host + '\'' +
", port=" + port +
'}';
}
}
config.properties
server.host=128.0.0.1
server.port=8080
VideoOrder.java

验证

Spring PropertySource,获取指定application.properties文件的更多相关文章
- Spring系列之——springboot解析resources.application.properties文件
摘要:本文通过讲解如何解析application.properties属性,介绍了几个注解的运用@Value @ConfigurationProperties @EnableConfiguration ...
- Spring Boot 中配置文件application.properties使用
一.配置文档配置项的调用(application.properties可放在resources,或者resources下的config文件夹里) package com.my.study.contro ...
- 是时候搞清楚 Spring Boot 的配置文件 application.properties 了!
在 Spring Boot 中,配置文件有两种不同的格式,一个是 properties ,另一个是 yaml . 虽然 properties 文件比较常见,但是相对于 properties 而言,ya ...
- 一:Spring Boot 的配置文件 application.properties
Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...
- SpringBoot读取application.properties文件
http://blog.csdn.net/cloume/article/details/52538626 Spring Boot中使用自定义的properties Spring Boot的applic ...
- 第二篇:彻底搞清楚 Spring Boot 的配置文件 application.properties
前言 在Spring Boot中,配置文件有两种不同的格式,一个是properties,另一个是yaml. 虽然properties文件比较常见,但是相对于properties而言,yaml更加简洁明 ...
- eclips环境下开发spring boot项目,application.properties配置文件下中文乱码解决方案
如以上,application.properties文件下中文乱码.发生乱码一般都是由于编码格式不一样导致的. 打开Window-Preferences-General-content Types-T ...
- spring boot项目,application.properties配置文件下中文乱码解决方案
转自:https://blog.csdn.net/qq_40408534/article/details/79831807 如以上,application.properties文件下中文乱码.发生乱码 ...
- spring boot 无法读取application.properties问题
spring boot 无法读取application.properties问题 https://bbs.csdn.net/topics/392374488 Spring Boot 之注解@Compo ...
- Spring Boot 的配置文件application.properties
Spring Boot 中的application.properties 是一个全局的配置文件,放在src/main/resources 目录下或者类路径的/config下. 作为全局配置文件的app ...
随机推荐
- Chrome 插件 V3 版本 Manifest.json 中的内容脚本(Content Scripts)解析
内容脚本(Content Scripts) 指定在用户打开某些网页时要使用的 JavaScript 或 CSS 文件. 内容脚本是在网页环境中运行的文件.通过使用标准文档对象模型 (DOM),开发者能 ...
- Chrome 浏览器插件 V3 版本 Manifest.json 文件中 Action 的类型(Types)、方法(Methods)和事件(Events)的属性和参数解析
一.类型(Types) 一.OpenPopupOptions 1. 属性 windowId: number 可选 打开操作弹出式窗口的窗口 ID.如果未指定,则默认为当前活动窗口. 二.TabDeta ...
- C 编程异常 — double free or corruption (fasttop)
问题:运行代码的时候程序崩溃. *** Error in `./parsing': double free or corruption (fasttop): 0x00000000023d2350 ** ...
- go高并发之路——缓存击穿
缓存击穿,Redis中的某个热点key不存在或者过期,但是此时有大量的用户访问该key.比如xxx直播间优惠券抢购.xxx商品活动,这时候大量用户会在某个时间点一同访问该热点事件.但是可能由于某种原因 ...
- linux文件的三个时间,修改文件时间为任意时间
目录 一.文件的三个时间 二.修改文件的三种时间为任意时间 一.文件的三个时间 当我们在linux中创建了文件或文件夹,文件/文件夹就有了时间属性,而且linux中的文件具有三个时间,可以通过stat ...
- 重温 ShardingSphere 分布策略
ShardingSphere--分片及策略:https://blog.csdn.net/weixin_38910645/article/details/107538848 Sharding-JDBC: ...
- 音视频学习--H264解析渲染
一.H264文件获取 下载一段MP4文件,通过FFMPEG转换成MP4 ffmpeg -i Gravity.mp4 -vcodec h264 out_2.264 二.通过解析H264成帧,然后刷新 这 ...
- 剑指Offer-55.链表中环的入口结点(C++/Java)
题目: 给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null. 分析: 利用快慢指针,如果链表中存在环的话,则快指针一定在环中的某个节点与慢指针相遇. 设头节点到链表的环的入口结点 ...
- NOIP 2023 三值逻辑
problem 我们定义 \(\text{T}\) 对应 \(n + 1\),\(\text{U}\) 对应 \(n + 2\),\(\text{F}\) 就是 \(-\text{T}\). 现在我们 ...
- Vector + ClickHouse 收集日志
目前业界的日志生态,最常用的是 ELK,其次就是 ClickHouse,本文会演示如何使用 Vector + ClickHouse 来采集 Nginx 日志并做清洗,最终写入 ClickHouse.至 ...