Spring Boot(3)---自定义spring boot starter 问题

1. "Failed to process import candidates for configuration class [com.simple.....]":java

主要缘由:spring

是由于本身定制的starter在打包时(package)用了spring-boot-maven-plugin,即在你的定制starter工程的pom.xml中有以下配置:maven

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>spring-boot

这样打出的包,就是按着spring boot的打包方式,Classpath设定,相对目录,资源目录等。当你用另外一个spring boot项目使用这个定制的starter的jar包时。就会有问题 ,由于认为你这个starter是一个普通的jar包。ui

这样就没法找到你的类定义。spa

解决办法:插件

删除自定义starter中的pom.xml中的打包插件设置,采用缺省的jar打包方式。便可解决这个问题。code

2.java.lang.IllegalArgumentException: Not an managed type: class .... ”xml

根本缘由:资源

是你用到的一些JPA,实体,及Repository类不是你spring boot启动文件所在的目录。致使JPA搜不到这些实体,Repository类。

解决办法:

在spring boot 的启动类中加入以下注解:

@EnableJpaRepositories("com.example.repository")//那些搜索不到的JPA相关的实体及Repository的包路径

@EntityScan("com.example.repository")

若是你用到了mongo的JPA还应该加上相对应的。

@EnableMongoRepositories("com.example.mongo")
@EnableJpaRepositories("com.example.repository")

@EntityScan("com.example.repository")

相关文章
相关标签/搜索