1 在application.properties中添加

android.name=Tim

android.password=123456

新建一个保存该Setting的配置类,

@ConfigurationProperties(prefix="android")

public class AndroidSettings {

private String name;

private String password;

//setters and getters

......

}

2 在自己的properties文件中添加

android.name=Tim

android.password=123456

@Component

@PropertySource("classpath:config/android.properties")

@ConfigurationProperties(prefix="android")

public class AndroidSettings {

private String name;

private String password;

//setters and getters

......

}

3 这两种方式都要在Spring boot的入口类上加上@EnableConfigurationProperties

@SpringBootApplication

@EnableConfigurationProperties(AndroidSettings.class)

public class DemoApplication {

public static void  main(String[] args) {

SpringApplication.run(DemoApplication.class, args);

}

}

4 使用定义的properties

@AutoWired

AndroidSettings androidSettings;

在spring boot中使用自定义的properties的更多相关文章

  1. Spring Boot中的自定义start pom

    start pom是springboot中提供的简化企业级开发绝大多数场景的一个工具,利用好strat pom就可以消除相关技术的配置得到自动配置好的Bean. 举个例子,在一般使用中,我们使用基本的 ...

  2. 如何优雅地在 Spring Boot 中使用自定义注解,AOP 切面统一打印出入参日志 | 修订版

    欢迎关注个人微信公众号: 小哈学Java, 文末分享阿里 P8 资深架构师吐血总结的 <Java 核心知识整理&面试.pdf>资源链接!! 个人网站: https://www.ex ...

  3. Spring Boot 中关于自定义异常处理的套路!

    在 Spring Boot 项目中 ,异常统一处理,可以使用 Spring 中 @ControllerAdvice 来统一处理,也可以自己来定义异常处理方案.Spring Boot 中,对异常的处理有 ...

  4. Spring Boot中如何自定义starter?

    Spring Boot starter 我们知道Spring Boot大大简化了项目初始搭建以及开发过程,而这些都是通过Spring Boot提供的starter来完成的.品达通用权限系统就是基于Sp ...

  5. Spring Boot中注入配置文件application.properties中的list 对象参数

    例如要注入下列参数: dyn.spring.datasources[0].name=branchtadyn.spring.datasources[0].driverClassName=oracle.j ...

  6. Spring Boot 中使用自定义注解,AOP 切面打印出入参日志及Dubbo链路追踪透传traceId

    一.使用背景 开发排查系统问题用得最多的手段就是查看系统日志,在分布式环境中一般使用 ELK 来统一收集日志,但是在并发大时使用日志定位问题还是比较麻烦,由于大量的其他用户/其他线程的日志也一起输出穿 ...

  7. Spring Boot中自定义注解+AOP实现主备库切换

    摘要: 本篇文章的场景是做调度中心和监控中心时的需求,后端使用TDDL实现分表分库,需求:实现关键业务的查询监控,当用Mybatis查询数据时需要从主库切换到备库或者直接连到备库上查询,从而减小主库的 ...

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

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

  9. Spring Boot2 系列教程(六)自定义 Spring Boot 中的 starter

    我们使用 Spring Boot,基本上都是沉醉在它 Stater 的方便之中.Starter 为我们带来了众多的自动化配置,有了这些自动化配置,我们可以不费吹灰之力就能搭建一个生产级开发环境,有的小 ...

随机推荐

  1. 配置php扩展redis

    环境说明: 系统版本    CentOS 6.9 x86_64 软件版本    nginx-1.12.2        php-5.5.38        yum安装redis3.2.11 php扩展 ...

  2. 转: 理解UDDI (from IBM Dev)

    from: http://www.ibm.com/developerworks/cn/webservices/ws-featuddi/index.html 何为 UDDI? UDDI 项目鼓励 Web ...

  3. java 中文转Unicode 以及 Unicode转中文

    package com.sun; public class Snippet {    public static void main(String[] args) {        String cn ...

  4. ajty

    ] .Tag //; ].Columns["NodeID"].ColumnName ; ].Tag)["NodeID"]; //(DataRow)row[&qu ...

  5. vector list map 遍历删除指定元素

    #include <stdio.h> #include <stdint.h> #include <vector> #include <list> #in ...

  6. 【转】oracle建立本地数据库

    来到公司的这段时间,在项目的开发过程中一直连接的是远程的oracle数据库,现在开始轮到自己做毕业设计了,自己想采用Oracle数据库,就想建立本地的数据库. 当然了,首先是自己先装Oracle客户端 ...

  7. URAL 1984. Dummy Guy(数学啊)

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1984 1984. Dummy Guy Time limit: 0.5 second Me ...

  8. Oracle LOB字段判空

    dbms_lob.getlength() dbms_lob.getlength(null) 会报错--- Oracle 默认为clob字段插入empty_clob()

  9. MySQL 字符编码总结

    今天操作服务器数据库时遇到了Mysql中文字符乱码的问题,主要原因是因为安装的时候没有设置好字符集. 很是郁闷,因为库里有很多重要数据,所以重装是不可能了,于是决定找找在不重装且不改代码的前提下,能搞 ...

  10. ubuntu 安装时出错 sudo apt-get update Reading package lists… Error

    安装过程出错 首先出现问题sudo apt-get updateReading package lists… Error!E: Encountered a section with no Packag ...