zoukankan      html  css  js  c++  java
  • spring boot添加自定义配置文件

    spring boot 2.+版本

    resources右键新建属性文件(new Resources Bundle),在新建属性文件中添加自定义属性

    新建一个操作类对该属性文件进关联,操作类须进行定义

    @PropertySource(value = "classpath:/myWebConfig.properties")
    @ConfigurationProperties(prefix = "web")

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


    操作类:
    import org.springframework.boot.context.properties.ConfigurationProperties;
    
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.PropertySource;
    import org.springframework.stereotype.Component;
    @Configuration
    @PropertySource(value = "classpath:myWebConfig.properties")
    @ConfigurationProperties(prefix = "web")
    public class MyWebConfig {
        private String sitename;
        //必须设置getter 和 setter
        public String getSitename() {
            return this.sitename;
        }
      
        public void setSitename(String s) {
            this.sitename = s;
        }
    }

    其他地方调用:

    @Autowired  //自动装配关联属性
    private MyWebConfig myWebConfig;
  • 相关阅读:
    Mac上反编译Android apk安装包
    静态链表
    x = x &(x-1)
    C语言itoa()函数和atoi()函数
    以文本方式和二进制方式操作文件
    自己实现memcpy,strcpy与strncpy
    实现中英文混合string的逆向输出
    实现纯英文string的逆序输出
    C语言实现字符串逆序输出
    ASCII码对照表
  • 原文地址:https://www.cnblogs.com/IsSshuai/p/11345728.html
Copyright © 2011-2022 走看看