zoukankan      html  css  js  c++  java
  • Repeated meta-data items

    B.2 Generating your own meta-data using the annotation processor

    You can easily generate your own configuration meta-data file from items annotated with @ConfigurationProperties by using thespring-boot-configuration-processor jar. The jar includes a Java annotation processor which is invoked as your project is compiled. To use the processor, simply include spring-boot-configuration-processor as an optional dependency, for example with Maven you would add:

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

    With Gradle, you can use the propdeps-plugin and specify:

    	dependencies {
    		optional "org.springframework.boot:spring-boot-configuration-processor"
    	}
    
    	compileJava.dependsOn(processResources)
    }
    [Note]

    You need to add compileJava.dependsOn(processResources) to your build to ensure that resources are processed before code is compiled. Without this directive any additional-spring-configuration-metadata.json files will not be processed.

    The processor will pickup both classes and methods that are annotated with @ConfigurationProperties. The Javadoc for field values within configuration classes will be used to populate the description attribute.

    [Note]

    You should only use simple text with @ConfigurationProperties field Javadoc since they are not processed before being added to the JSON.

    Properties are discovered via the presence of standard getters and setters with special handling for collection types (that will be detected even if only a getter is present). The annotation processor also supports the use of the @Data@Getter and @Setter lombok annotations.

    B.2.1 Nested properties

    The annotation processor will automatically consider inner classes as nested properties. For example, the following class:

    @ConfigurationProperties(prefix="server")
    public class ServerProperties {
    
        private String name;
    
        private Host host;
    
        // ... getter and setters
    
        private static class Host {
    
            private String ip;
    
            private int port;
    
            // ... getter and setters
    
        }
    
    }

    Will produce meta-data information for server.nameserver.host.ip and server.host.port properties. You can use the @NestedConfigurationPropertyannotation on a field to indicate that a regular (non-inner) class should be treated as if it were nested.

    B.2.2 Adding additional meta-data

    Spring Boot’s configuration file handling is quite flexible; and it often the case that properties may exist that are not bound to a @ConfigurationProperties bean. To support such cases, the annotation processor will automatically merge items from META-INF/additional-spring-configuration-metadata.json into the main meta-data file.

    The format of the additional-spring-configuration-metadata.json file is exactly the same as the regular spring-configuration-metadata.json. The additional properties file is optional, if you don’t have any additional properties, simply don’t add it.

    http://docs.spring.io/spring-boot/docs/1.3.0.M1/reference/html/configuration-metadata.html#configuration-metadata-annotation-processor

  • 相关阅读:
    (转)使用BigDecimal进行精确运算
    date——sql查询
    (转)每天一个linux命令(8):cp 命令,复制文件和文件夹
    (转)每天一个linux命令(15):tail 命令
    (转)Linux 下 查看以及修改文件权限
    (转)用JUnit4进行单元测试
    (转)Spring Boot Junit单元测试
    (转)ZXing解析二维码
    (转)ZXing生成二维码和带logo的二维码,模仿微信生成二维码效果
    (转)js jquery.qrcode生成二维码 带logo 支持中文
  • 原文地址:https://www.cnblogs.com/softidea/p/5754918.html
Copyright © 2011-2022 走看看