添加生成元数据信息的依赖
org.springframework.boot spring-boot-starter 2.1.6.RELEASE org.springframework.boot spring-boot-configuration-processor 2.1.6.RELEASE true
配置类
@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 Mapinfo; public Map getInfo() { return info; } public void setInfo(Map 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)@Configurationpublic 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中便可配置.