Springboot--关于自定义stater的yml无法提示

1.前言

在以前在搭建架构的时候就碰到了类似的情况,在使用@EnableConfigurationProperties注解的时候,不管怎样,在项目中引入了该starter的情况下依然不发自动的提示properties里面的属性。

@Data
@ConfigurationProperties(prefix = "properties")
public class DefaultProperties {

    @NestedConfigurationProperty
    public SwaggerProperties swagger;
}

--------以上为properties
properties:
  swagger:
    type: service
    packages: com.wsq.controller
    api-tittle: 'swagger文档'
    service-url:
    writer-name: 'wangqueyue'
    version: '1.0.0'
------无法识别,只能一个个的敲击。

2.解决方案

2.1引入依赖包

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

2.2配置idea

网上讲解的创建spring-configuration-metadata.json,这个文件过于繁琐,手动写基本不可能,所以这里有简单的生成方式,生成后只需要加以修改就行。

setting>Build,execution,deployment>Compiker>Annotation Processors

勾选Enable annotation processing

2.3打包编译starter(重点)

  • 编译时必须得maven clean,不然上次你编译打包的东西有误你自己还认为是正确的。
  • 然后maven compile(切记,starter的类型必须为jar,不能为pom)
  • maven install,必须要将项目打包到本地服务。

在target目录下,会生成一个spring-configuration-metadata.json文件,不需要手动创建了,有的你在starter创建了,没有打包仍然无效。

2.4additional-spring-configuration-metadata.json文件创建

这个文件是对上一个文件的补充说明,创建方式也很简单

  • 将target目录下的spring-configuration-metadata.json文件复制到resource目录下的META-INF下,没有直接创建就行。
  • 将文件改成标题的名字,继续maven clean ,compile,install。
  • target目录下会生成一个additional-spring-configuration-metadata.json文件,这样补充文件就完成了。

猜你喜欢

转载自blog.csdn.net/wangshiqi666/article/details/130903341
今日推荐