简体   繁体   中英

Spring boot starter annotation metadata

In the Spring Boot documentation in the chapter "Writing our own spring boot starter" is written:

Make sure to trigger meta-data generation so that IDE assistance is available for your keys as well.

Ok, I can make it generated by something like this:

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

But why ? What is the purpose of such metadata, where can i find them and more importanly what they have to do with my IDE ( I am using spring tool suite) ? I simply want to use my own properties like kulatamicuda.superitem in application properties.

Can somebody explain it to me ? I am little bit confused. Thank you.

The purpose is the same as writing javadocs for your interfaces I believe.

So in case you are creating this starter with intention for other peoples to use it, then there should be some documentation for it.

When you are creating a library you probably understand that you should document at least interfaces which other developers can use in their applications.

Similar thing here, your ide(at least IDEA) will try to find META-INF/spring-configuration-metadata.json file in your artefact, and will provide autocompletion and description(which you will specify in this file) for this properties.

Here is an example: https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html

However if you don't want to describe these properties, then you can leave it as it is without creating any files with meta information, it wouldn't affect your application.

Here is how it works in IDEA:

在此处输入图片说明

You can see that there is autocompletion and description for each property defined in springboot starters added for this project. Also it knows about the type of property and its default value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM