zoukankan      html  css  js  c++  java
  • 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中便可配置.

  • 相关阅读:
    poj 2046 Power Strings KMP
    谈谈需求变更的用户签字确认问题
    Oracle 10g客户端 安装(配图)
    如何让有能力的下属承担更多职责
    软件性能测试工具在测试工作中的重要性
    Oracle 10g 服务器端 安装图解
    JS 操作页面基础操作:禁止另存 防止复制 防止选择
    Javascript 长整型 转 C# DateTime
    配置AJAX Enabled WCF在hosting时: Showing the serviceMetadata in an ASP.NET AJAX Service
    ICON资源网站
  • 原文地址:https://www.cnblogs.com/snow-man/p/11169777.html
Copyright © 2011-2022 走看看