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>
重新编译后,在配置文件中生效了
问题解决,附上代码示例