• 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中的配置
    如果active中有与在application的相同的配置会覆盖在application中的配置

  • 相关阅读:
    四则运算1
    四则运算3
    数组1
    四则运算单元测试
    四则运算2
    数组3
    数组2
    spring aop对service层日志和异常的处理
    Linux设置开机启动
    数据仓库开发——Kettle使用示例
  • 原文地址:https://www.cnblogs.com/fly-book/p/11563008.html
Copyright © 2020-2023  润新知