这些文章不错:
SpringBoot+Mybatis多模块(module)项目搭建教程
SpringBoot之多module项目创建
搭建完毕应用分层如下:
问题1:项目启动后就立即关闭(Process finished with exit code 0)
idea搭建maven项目时,会默认一个springboot版本,笔者是version:2.1.5,网上描述该版本仍存在一些bug,故尝试使用以前稳定版本,即在pom.xml中修改配置,如
问题2:包冲突
项目搭建过程中遇到spring-boot-starter-web包冲突的问题,包冲突有两个表现:一是右侧maven管理的Dependencies中显示包“unknown”,一是在启动时idea提示让引入相应配置。解决如下
第一步:清除本地的镜像中的包(.m2/repository/org/springframework/spring-web)
第二步:然后清除idea的缓存并重新启动即可(File / Invalidate Caches / Restarts...)
问题3:Unable to find main class
Spring Boot Maven Plugin插件进行打包,若未指定mainClass时,打包过程报错“Unable to find main class”,此时有两种解决办法
方法1:指定mainClass(此时子module下java目录可为空)
org.springframework.boot
spring-boot-maven-plugin
com.example.demo.web.WebApplication
repackage
方法2:子module中添加相应的 main入口类
public class test {
public static void main(String args[]){};
}
这篇文章不错:Spring Boot Maven Plugin打包异常及三种解决方法:Unable to find main class
问题4:循环依赖问题
打包编译过程时,出现了循环依赖问题。感觉很疑惑,除子module继承主module外,其实并没有任何相互依赖的地方,最后发现是主module要使用
这篇文章不错: Maven 中 dependencyManagement 标签使用
The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.example:test:0.0.1-SNAPSHOT'}' and 'Vertex{label='com.example:test-service:0.0.1-SNAPSHOT'}' introduces to cycle in the graph com.example:test-service:0.0.1-SNAPSHOT --> com.example:test-web:0.0.1-SNAPSHOT --> com.example:test:0.0.1-SNAPSHOT --> com.example:test-service:0.0.1-SNAPSHOT ->
问题5:包扫描配置
service层定义服务时,如@Service、@Controller、@Reposity等标签定义,若想正常使用,则需要在@SpringBootApplication属性中配置启动扫描包,即通过scanBasePackages来定义应用启动时初始化哪些controller
问题6:子module间依赖问题
子module间若存在依赖,对其进行打包编译时,出现依赖包找不到的情况,提示在本地镜像库找不到或者存在缓存什么的,此时对主module打包编译后发布(install)即可
Failed to execute goal on project test-web: Could not resolve dependencies for project com.example:test-web:jar:0.0.1-SNAPSHOT: Could not find artifact com.example:test-service:jar:0.0.1-SNAPSHOT in nexus-releases (http://nexus.dadaabc.us/nexus/content/repositories/public/)
Failed to execute goal on project test-web: Could not resolve dependencies for project com.example:test-web:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.example:test-service:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com.example:test-service:jar:0.0.1-SNAPSHOT: Failure to find com.example:test:pom:0.0.1-SNAPSHOT in http://nexus.dadaabc.us/nexus/content/repositories/public/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus-releases has elapsed or updates are forced
其它一些莫名其妙的问题,重启idea,清除缓存试试