02.自定义banner、全局配置文件、@Value获取自定义配置、@ConfigurationProperties、profiles配置

时间:2019-09-21
本文章向大家介绍02.自定义banner、全局配置文件、@Value获取自定义配置、@ConfigurationProperties、profiles配置,主要包括02.自定义banner、全局配置文件、@Value获取自定义配置、@ConfigurationProperties、profiles配置使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

自定义banner

  • src/main/resource 下新建 banner.txt,字符复制到banner.txt 中
  • 生成字符网站推荐:
    http://patorjk.com/software/taag
    https://www.bootschool.net/ascii

    全局配置文件

  • src/main/resource 下新建 application.yml 或 application.properties
    application.properties:
server.port=8090
# 以【localhost】/fly 开头
server.context-path=/fly
  • application.yml:
server:
  port: 8090

读取自定义配置--@Value获取

application.properties中定义

app.author=fly

使用 @Value获取

import org.springframework.beans.factory.annotation.Value;

  @Value("${app.author}")
    private String author;

读取自定义配置--@ConfigurationProperties

import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "app")
public class xxx{
    private String author;
    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }
}

profiles配置

在application.properties中配置spring.profiles.active=dev就会读取
application-dev.properties中的配置

原文地址:https://www.cnblogs.com/fly-book/p/11563008.html