官方提供的spring boot starter的配置项,我们用IDE配置的时候一般都有自动提示的,如下图所示
而我们自己自定义的配置却没有,对开发非常不友好容易打错配置,那这个是怎样实现的呢?
IDE是通过读取配置信息的元数据而实现自动提示的,而元数据在目录META-INF
中的spring-configuration-metadata.json
或者 additional-spring-configuration-metadata.json
以我这个自己开发的starter中的自定义配置文件为例,如果自己手动创建这些元数据的话工作量比较大,使用IDEA
的话有自动生成功能
在zlt-swagger2-spring-boot-starter
工程中添加以下jar包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency>
搜索Annotation Processor
并设置Enable annotation processing
项目在重新编译后就会自动生成spring-configuration-metadata.json
文件
自定义的swagger配置已经能自动提示了
参考资料 https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html
本文分享自微信公众号 - 陶陶技术笔记(zltrobin),作者:陶陶
原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。
原始发表时间:2019-08-27
本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。
我来说两句