手写SpringBoot Starter 配置文件在yml无智能提示

1. 手写的starter中的自定义properties配置内容,在SpringBoot的yml文件无智能提示

@ConfigurationProperties(prefix = "yxxmg.pay")
@Data
public class YxxmgPayProperties {
    PayMethod payMethod;
}
@Configuration
@ConditionalOnMissingBean(PayService.class)
@EnableConfigurationProperties(YxxmgPayProperties.class)
public class YxxmgPayAutoConfigure {
    @Bean
    public PayService payService(YxxmgPayProperties yxxmgPayProperties) {
        ServiceLoader<PayService> serviceLoader = ServiceLoader.load(PayService.class);
        Iterator<PayService> iterator = serviceLoader.iterator();
        PayService payService = null;
        while (iterator.hasNext()) {
            payService = iterator.next();
            if (payService instanceof AlipayServiceImpl && PayMethod.ALIPAY.equals(yxxmgPayProperties.getPayMethod())) {
                break;
            }
            if (payService instanceof UnionPayServiceImpl && PayMethod.UNION.equals(yxxmgPayProperties.getPayMethod())) {
                break;
            }
            if (payService instanceof WechatPayServiceImpl && PayMethod.WECHAT.equals(yxxmgPayProperties.getPayMethod())) {
                break;
            }
            if (Objects.isNull(payService)) {
                payService = new ErrorPayServiceImpl();
            }
        }
        return payService;
    }
}

在application.yml无任何提示信息


2. 解决方案

Configuration Metadata官网给的解决方案

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

 pom文件引入上述配置后

有些人配置好后,maven clean package install后就成功。

但是我编译后未产生spring-configuration-metadata.json文件说明哪边还是有问题

这个问题困扰了很久,编译未产生那说明我们maven配置的编译可能存在问题

打开父pom.xml文件发现下面一段内容

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                        <!-- This is needed when using Lombok 1.18.16 and above -->
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok-mapstruct-binding</artifactId>
                            <version>${lombok-mapstruct-binding.version}</version>
                        </path>
                        <!-- Mapstruct should follow the lombok path(s) -->
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

annotationProcessorPaths中设置了lombok以及mapstruct相关内容

那就把spring-boot-configuration-processor也配置进去

<path>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-configuration-processor</artifactId>
  <version>${configuration-processor.version}</version>
</path>

重新编译后,在配置文件中生效了

问题解决,附上代码示例

java-practices: Mybatis-Plus、Knife4j、JSR330、JSR303、SPI、Mapstruct、Caffeine、JustAuth、Openfeign、easy-es、easy-excel - Gitee.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

游侠小马哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值