栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

properties配置文件配置

properties配置文件配置

背景说明

项目部署到不通服务器时,对应的配置文件可能不相同,比如:读入节目文件的访问地址等。故需要将项目某些配置文件与原有项目解耦,使得部署项目更加灵活。

maven依赖

    org.springframework.boot
    spring-boot-configuration-processor
    true

配置文件内容
# [server]
device.base_url=v1/api/
device.device_set_attribute=/setDeviceAttribute
device.device_get_attribute=/getDeviceAttribute
device.device_get_device_list_type=/getDeviceListByType
device.device_get_device_info=/getDevice
device.device_add_invoke=/insertInvoke
device.device_count_attribute_data=/getDeviceAttribute/list
device.device_get_last_invoke=/getLastDeviceInvoke
配置文件读取类

注意事项 config.path是配置在application.properties的配置文件绝对路劲

package com.dm.core.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@EnableConfigurationProperties(SystemDeviceApi.class)
@ConfigurationProperties(prefix = SystemDeviceApi.SYSTEM_base_CONFIG_PREFIX,ignoreInvalidFields = true)
// 第一种配置方案,配置文件存放在配置文件夹resources目录下,config是配置文件夹下面的子目录
@PropertySource(value = {"classpath:config/SystemDeviceApi.properties"},
// 第二中配置方案,${config.path}为配置文件绝对路径,可以使用项目以外目录                
//@PropertySource(value = {"file:${config.path}SystemDeviceApi.properties"},
        ignoreResourceNotFound = false, encoding = "UTF-8", name = "SystemDeviceApi.properties")
@Data
public class SystemDeviceApi {
    public static final String SYSTEM_base_CONFIG_PREFIX = "device";
    private String baseUrl;
    private String deviceSetAttribute;
    private String deviceGetAttribute;
    
    private String deviceGetDeviceListType;
    private String deviceGetDeviceInfo;
    
    private String deviceAddInvoke;
    private String deviceCountAttributeData;
    
    private String deviceGetLastInvoke;

}

application.properties配置文件内容

config.path=F:/properties/
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/707307.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号