栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

spring 自定义的配置文件

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

spring 自定义的配置文件

springboot 自定义的配置文件 启动类加上此注解;

@EnableConfigurationProperties({CustomProperties.class})

新建test.properties文件
custom.jenkinsurl=http://10.10.5.100:18080/jenkins
custom.jenkins_username=admin
custom.jenkins_password=qwertyui!
custom.winrar_path=D:\soft\winrar\WinRAR.exe
新建配置文件对应的实体类
package com.cloudtest.businessinspectionApi.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@PropertySource(value = "classpath:config/configs.properties")
@Component
@ConfigurationProperties(prefix = "custom")
public class CustomProperties {
    public String jenkins_username;
    public String jenkins_password;
    public String winrar_path;
    public String jenkinsUrl;
    public String getJenkinsUrl() {
        return jenkinsUrl;
    }
    public void setJenkinsUrl(String jenkinsUrl) {
        this.jenkinsUrl = jenkinsUrl;
    }
    public String getJenkins_username() {
        return jenkins_username;
    }
    public void setJenkins_username(String jenkins_username) {
        this.jenkins_username = jenkins_username;
    }
    public String getJenkins_password() {
        return jenkins_password;
    }
    public void setJenkins_password(String jenkins_password) {
        this.jenkins_password = jenkins_password;
    }
    public String getWinrar_path() {
        return winrar_path;
    }
    public void setWinrar_path(String winrar_path) {
        this.winrar_path = winrar_path;
    }
    @Override
    public String toString() {
        return "CustomProperties{" +
                "jenkins_username='" + jenkins_username + ''' +
                ", jenkins_password='" + jenkins_password + ''' +
                ", winrar_path='" + winrar_path + ''' +
                ", jenkinsUrl='" + jenkinsUrl + ''' +
                '}';
    }
}
引用的方式
String jenkinsUrl = customProperties.getJenkinsUrl();
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1023416.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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