@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文件的更多相关文章

  1. Spring系列之——springboot解析resources.application.properties文件

    摘要:本文通过讲解如何解析application.properties属性,介绍了几个注解的运用@Value @ConfigurationProperties @EnableConfiguration ...

  2. Spring Boot 中配置文件application.properties使用

    一.配置文档配置项的调用(application.properties可放在resources,或者resources下的config文件夹里) package com.my.study.contro ...

  3. 是时候搞清楚 Spring Boot 的配置文件 application.properties 了!

    在 Spring Boot 中,配置文件有两种不同的格式,一个是 properties ,另一个是 yaml . 虽然 properties 文件比较常见,但是相对于 properties 而言,ya ...

  4. 一:Spring Boot 的配置文件 application.properties

    Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...

  5. SpringBoot读取application.properties文件

    http://blog.csdn.net/cloume/article/details/52538626 Spring Boot中使用自定义的properties Spring Boot的applic ...

  6. 第二篇:彻底搞清楚 Spring Boot 的配置文件 application.properties

    前言 在Spring Boot中,配置文件有两种不同的格式,一个是properties,另一个是yaml. 虽然properties文件比较常见,但是相对于properties而言,yaml更加简洁明 ...

  7. eclips环境下开发spring boot项目,application.properties配置文件下中文乱码解决方案

    如以上,application.properties文件下中文乱码.发生乱码一般都是由于编码格式不一样导致的. 打开Window-Preferences-General-content Types-T ...

  8. spring boot项目,application.properties配置文件下中文乱码解决方案

    转自:https://blog.csdn.net/qq_40408534/article/details/79831807 如以上,application.properties文件下中文乱码.发生乱码 ...

  9. spring boot 无法读取application.properties问题

    spring boot 无法读取application.properties问题 https://bbs.csdn.net/topics/392374488 Spring Boot 之注解@Compo ...

  10. Spring Boot 的配置文件application.properties

    Spring Boot 中的application.properties 是一个全局的配置文件,放在src/main/resources 目录下或者类路径的/config下. 作为全局配置文件的app ...

随机推荐

  1. three.js介绍和学习资料说明

    1.three.js能做什么 Three.js是基于原生WebGL封装运行的三维引擎,在所有WebGL引擎中,Three.js是国内文资料最多.使用最广泛的三维引擎.既然Threejs是一款WebGL ...

  2. C++ 类的继承(Inheritance)

    一.继承(Inheritance) C++有一个很好的性质称为inheritance(继承),就是声明一个class(derived class),把另一个或多个class(base class)的所 ...

  3. Chrome 浏览器插件 Manifest.json V3 中权限(Permissions)字段解析

    一.权限(Permissions) 再使用拓展程序的 API 时,大多数的时候,需要在 manifest.json 文件中声明 permissions 字段. 一.权限类型 在 V3 版本中可以声明以 ...

  4. Linux上执行内存中的脚本和程序

    在Linux中可以不需要有脚本或者二进制程序的文件在文件系统上实际存在,只需要有对应的数据在内存中,就有办法执行这些脚本和程序. 原理其实很简单,Linux里有办法把某块内存映射成文件描述符,对于每一 ...

  5. centos安装kvm博客

    一 centos如何安装kvm https://blog.csdn.net/yulsh/article/details/91790804

  6. .net core 关于对swagger的UI(Index.html)或接口的权限验证;

    背景: 如何在ASP.Net Core的生产环境中保护swagger ui,也就是index.html页面.其实swagger是自带禁用的功能的,只需要设置开关即可.但是有一些场景,是需要把这些接口进 ...

  7. MySQL查看实时执行的SQL语句

    MySQL默认不能实时查看执行的SQL语句,因为这会消耗一定的资源. 要开启这个功能,稍微配置一下,打开这个LOG记录就可以了. 1 查看LOG功能 首先,查看是否已经开启实时SQL语句记录. mys ...

  8. ajax 请求接口实例

    通过 HTTP 请求加载远程数据. jQuery 底层 AJAX 实现.简单易用的高层实现见 $.get, $.post 等.$.ajax() 返回其创建的 XMLHttpRequest 对象.大多数 ...

  9. wireshark常见使用技巧

    (1)wireshark根据报文不同字段排序 举例说明:现在有50000个1588 sync报文,我想根据报文的originalTimestamp(seconds)字段进行排序,该如何操作呢? 操作过 ...

  10. JAVA IDEA Maven 加速镜像 阿里云

    JAVA IDEA Maven 加速镜像 阿里云 如果是IDEA自带的则在: C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 20 ...