@windwolf
2019-09-30T06:33:45.000000Z
字数 4938
阅读 1566
Sailing
升级期间添加以下依赖, 增加很多提示信息, 升级完去除
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-properties-migrator</artifactId><scope>runtime</scope></dependency>
统一使用
org.springframework.util.StringUtils
@NotNull缺失
添加依赖
<dependency><groupId>org.jetbrains</groupId><artifactId>annotations</artifactId><version>13.0</version></dependency>
仅在需要指定其他配置文件的时候使用@PropertySource, application.properties和application-XXX.properties不用加, 自动的.
重要: 使用@PropertySource的时候, 不要加classPath前缀, 确保按照spring framework的默认规则加载配置文件
启动报错 The bean 'jsonSerializer', defined in class path resource [springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class], could not be registered.
spring framework 5默认禁止bean注册覆盖, 要么配置文件中开起来, 要么定义的时候换个名字.
为了尽量减少意外印象, JsonSerializer都为静态方法, 取消注册
json反序列化的时候报错, 找不到构造函数啥的.
项目根目录创建一个叫lombok.config的文件
文件的内容如下:
config.stopbubbling = truelombok.noargsconstructor.extraprivate = truelombok.anyConstructor.addConstructorProperties = true
自定义配置项命名relatedCompnay不规范
不能出现大写, 单词之间用减号 - 风格.
配置项目大量调整
主要是命名空间调整
各种编译报错
org.springframework.boot.web.support改成org.springframework.boot.web.servlet.support;
EmbeddedServletContainerCustomizer不存在了
重写, 实现
WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>
@Componentpublic static class TomcatCustomizer implements > WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {@Overridepublic void customize(ConfigurableServletWebServerFactory server) {server.setPort(9000);if (server instanceof TomcatServletWebServerFactory) {TomcatServletWebServerFactory tomcat = (TomcatServletWebServerFactory) server;tomcat.addContextCustomizers(context -> context.setCookieProcessor(new LegacyCookieProcessor()));}}}
启动报错 spring boot 2 Invocation of init method failed; nested exception is org.hibernate.boot.archive.spi.ArchiveException: Could not build ClassFile
是因为spring boot的版本和spring cloud的对不上
spring cloud Greenwich版本对应spring boot 2.1.X
feign依赖的代码报错
改成依赖openfeign
org.springframework.cloud.netflix.feign包中的东西移到了org.springframework.cloud.openfeign中
tomcatCustomize报错
重写, 实现
WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>接口
使用jpa自带的hibernate版本
去除
<dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>5.2.9.Final</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-entitymanager</artifactId><version>5.2.9.Final</version></dependency>
启动报错 org.hibernate.boot.archive.spi.ArchiveException: Could not build ClassFile ... java.io.IOException: invalid constant type: 18 at 23
javassist存在版本冲突, 替换依赖包
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId><exclusions><exclusion><artifactId>javassist</artifactId><groupId>org.javassist</groupId></exclusion></exclusions></dependency><dependency><groupId>org.javassist</groupId><artifactId>javassist</artifactId><version>3.24.1-GA</version><scope>runtime</scope></dependency>
编译错误, jpaProperty.getHibernateProperties不存在
注入
HibernateProperties, 创建EntityManagerFactoryBean时, 改成这样:
@Primary@Bean(name = DEFAULT_ENTITYMANAGERFACTORY_NAME)public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, DataSource dataSource) > {Map<String, Object> properties = hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), new HibernateSettings());return builder.dataSource(dataSource).properties(properties).packages("com.qstech.sailing.modules", "com.qstech.sailing.domain", "com.qstech.sailing.framework").persistenceUnit("mainPersistenceUnit").build();}
mongodb相关报错
因为目前已经没有使用mongodb了, 相关实现也非常老旧, 全部去除
page相关API的参数类型报错
些是int, 有些是long, 要调整
Repository.findOne, delete报错
api变了, findONe改成getOne; delete改成deleteById
oauth部分各种报错
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-oauth2-resource-server</artifactId></dependency><dependency><groupId>org.springframework.security.oauth</groupId><artifactId>spring-security-oauth2</artifactId><version>2.3.6.RELEASE</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency>
org.springframework.security.authentication.encoding.Md5PasswordEncoder不存在了
替换用到MD5的地方的实现, 可以替换成
Md5Crypt.apr1Crypt
quartz和spring boot整合
去掉原来的quartz相关的依赖. 添加依赖:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-quartz</artifactId></dependency>
原来的Configuration不再需要
start-on-boot选项不在需要, 内置的spring.quartz.auto-start起这个作用.
spring boot有个bug, 使用@QuartzDataSource自定义的数据源会被默认数据源覆盖. 以下用法用于绕过这个问题:
后台任务明明表里面有, 但不执行
原因是schedName对不上. 原来的实现由bug, 其实quartz.xxx.properties配置文件没有起作用, 导致SchedulerName永远是默认的, 针对boot2调整后, 配置文件起作用了, 而配置文件里面的名称和数据库里的对不上. 将配置文件里的名称改为
schedulerFactoryBean
feign-form,feign-form-spring这两个依赖包升级到3.8.0. config的地方, 改:
@Bean@Primary@Scope("prototype")public Encoder multipartFormEncoder() {return new SpringFormEncoder();}