zoukankan      html  css  js  c++  java
  • springboot下自定义配置文件,并在项目里读取的方法

    首先

    pom文件引入springboot文件处理器

        <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-configuration-processor</artifactId>
                <optional>true</optional>
            </dependency>

    resources下编写自定义配置文件

    内容如下:

    xdqUrl.equUrl=http://172.26.1.33:8080/xdq/substation/find_equipments
    
    xdqUrl.equTableUrl=http://172.26.1.33:8080/xdq/sysTableInfo/find_tableId
    
    xdqUrl.equValueUrl=http://172.26.1.33:8080/xdq/sysTableInfo/find_YCYXValue

    编写自定义配置文件属性类,用来对应配置文件参数

    package com.qif.xdqdm.config;
    
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.context.annotation.PropertySource;
    import org.springframework.stereotype.Component;
    
    /**
     * @Title: UrlBeanProp
     * @ProjectName xdqdm
     * @Description: TODO
     * @date 2019/8/2  9:44
     */
    
    
    @Component
    @ConfigurationProperties(prefix = "xdqUrl")
    @PropertySource(value = "classpath:url.properties")
    public class UrlBeanProp {
    
    
        private String equUrl;
        private String equTableUrl;
        private String equValueUrl;
    
    
        public String getEquUrl() {
            return equUrl;
        }
    
        public void setEquUrl(String equUrl) {
            this.equUrl = equUrl;
        }
    
        public String getEquTableUrl() {
            return equTableUrl;
        }
    
        public void setEquTableUrl(String equTableUrl) {
            this.equTableUrl = equTableUrl;
        }
    
        public String getEquValueUrl() {
            return equValueUrl;
        }
    
        public void setEquValueUrl(String equValueUrl) {
            this.equValueUrl = equValueUrl;
        }
    }

    综上配置完毕

    项目中可以直接用  

    urlBeanProp.getEquValueUrl() 获取参数:
    http://172.26.1.33:8080/xdq/substation/find_equipments
  • 相关阅读:
    linux系统原子操作
    linux驱动编写之进程独占驱动
    批处理文件配置网络
    linux驱动编写之中断处理
    BusyBox下tftp命令的使用
    linux应用编程之进程间同步
    linux创建线程之pthread_create
    PHP 实现自动加载
    Swoole PHP windows composer
    win7&win10 右键添加 cmd
  • 原文地址:https://www.cnblogs.com/MagicAsa/p/11288949.html
Copyright © 2011-2022 走看看