SpringBoot1.5.9使用了近两年,最近有个新项目,开始着手将框架升级为SpringBoot2.X。
坑1:SpringData JPA API变更
这点还好,因为做了基类封装,只需对将基类进行少许修改。这部分的新特性请参考官网或网上其他文章。
坑2:SpringSecurity API变更
原本就对花了好大力气才搞定基于SpringSecurity Oauth2的RBAC,结果升级一下Springboot,又TM用不了了。倒腾了一番,无果,最终自己用Interceptor+Redis实现了一套。PS:慎用Spring全家桶。
坑3:Gradle需要升级到4.4+
坑4:lombok无法import
项目用的gradle多模块结构。之前将lombok的依赖放在公共子模块common里,其他项目compile project(':common'),升级后依赖是下载了的,但项目里死活没法import。几小时的百度加看官网文档后,将依赖提到build.gradle的subprojects下:
subprojects {
apply plugin: 'idea'
/**
* 在此声明公用插件
*/
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
/**
* 在此声明源文件和目标文件编译后的Java兼容版本
*/
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
/**
* 在此声明项目依赖的仓库
*/
repositories {
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}")
}
}
/**
* 在此声明所有子项目依赖的类库
*/
dependencies {
testCompile("junit:junit:${junitVersion}")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
}
问题解决。
坑5:打包命令由原来的bootRepackage变为了bootJar|bootWar
坑6:Idea运行没问题,gradle bootJar|build时报依赖的子项目包不存在package xxx does not exist、找不到符号cannot find symbol。最终参考CSDN上的“解决gradle多模块依赖在Idea中能运行,gradle build失败的问题”
https://blog.csdn.net/easewalk/article/details/84867043
和spring官网
https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/gradle-plugin/reference/html/
两篇文章,在作为库的非运行子项目的build.gradle里加上
jar {
enabled = true
}
问题得到解决。