• spring-boot ConfigurationProperties


    添加生成元数据信息的依赖

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

    配置类

    @ConfigurationProperties(prefix = "feilong.hello.format",ignoreUnknownFields = true)
    public class HelloFormatProperties {
    
        private  int port;
    
        public int getPort() {
            return port;
        }
    
        public void setPort(int port) {
            this.port = port;
        }
    
        public final static String HELLO_FORMAT_PROPERTITIES = "feilong.hello.format";
        private Map<String, Object> info;
    
        public Map<String, Object> getInfo() {
            return info;
        }
    
        public void setInfo(Map<String, Object> info) {
            this.info = info;
        }
    
        @Override
        public String toString() {
            return "HelloFormatProperties{" +
                    "info=" + info +
                    '}';
        }
    }

    作为自动化配置项, [启动@EnableConfigurationProperties]

    @Import(feilong.stater.autoconfiguration.FormatAutoConfiguration.class)
    @EnableConfigurationProperties(feilong.stater.autoconfiguration.HelloFormatProperties.class)
    @Configuration
    public class HellowAutoConfiguration {
    
        @Bean(name="feilonghelloFormatTemplate")
        public feilong.stater.HelloFormatTemplate helloFormatTemplate(feilong.stater.autoconfiguration.HelloFormatProperties helloProperties, feilong.stater.format.IFormatProcessor formatProcessor){
            return new feilong.stater.HelloFormatTemplate(helloProperties,formatProcessor);
        }
    }

     在resources/META-INF/spring.factories下配置自动注入类

    org.springframework.boot.autoconfigure.EnableAutoConfiguration=  
      feilong.stater.autoconfiguration.HellowAutoConfiguration
    

      

    最后一步打包成jar,放到私服上.供其他项目引用

    注意,打包时会在spring.factories下生成元数据:spring-configuration-metadata.json

    这样在其他springboot项目中,application.properties中便可配置.

  • 相关阅读:
    idea git 操作
    1
    python 迭代器/生成器/迭代对象
    python 中的type
    systemd 配置文件
    python 中类的初始化过程
    mysql主从错误180301
    从零开始搭建k8s-20180301
    kubernetes role
    Java程序员毕业两年自述
  • 原文地址:https://www.cnblogs.com/snow-man/p/11169777.html
Copyright © 2020-2023  润新知