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中便可配置.

 

转载于:https://www.cnblogs.com/snow-man/p/11169777.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值