springboot 自定义starter包,在项目中引用,启动报错。
org.springframework.boot.SpringApplication [SpringApplication.java:843] Application run failed
java.lang.IllegalStateException: Unable to read meta-data for class com.hxg.mail.springboot.config.HxgMailAutoConfigure
查看项目中的jar依赖引用,发现未包含自己定义的配置类,如下图
查看springboot starter包中的target目标,也没有配置类
查看springboot官网,springboot3的配置方式为
Spring Boot checks for the presence of a META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
file within your published jar. The file should list your configuration classes, with one class name per line, as shown in the following example:
com.mycorp.libx.autoconfigure.LibXAutoConfiguration com.mycorp.libx.autoconfigure.LibXWebAutoConfiguration
即META-INF目标下创建spring目录,然后创建org.springframework.boot.autoconfigure.AutoConfiguration.imports文件,将配置类写入该文件。
改变配置类后依旧出现问题,后来发现springboot3依赖的是jdk17,我本地安装的是jdk12,将springboot版本改为springboot2后,打包正常。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.5.3</version>
</dependency>