org.springframework.data.mongodb.UncategorizedMongoDbException
Command failed with error 301: 'Retryable writes are not supported' on server *.com: 27017. The full response is
{"ok": 0.0, "code": 301, "errmsg": "Retryable writes are not supported", "operationTime": {"$timestamp": {"t": 1637724972, "i": 1
nested exception is com.mongodb.MongoCommandException: Command failed with error 301: 'Retryable writes are not
supported' on server *.com: 27017. The full response is {"ok": 0.0, "code": 301, "errmsg": "Retryable writes are not supported", "operationTime": {"$timestamp": {"t": 1637724972, "i": 1
在3.6版本的java mongo driver中,新增了retryWrites.
升级过程刚好是跨过一个没有retryWrites到有的过程,所以出现错误.
在mongo 连接的uri中指定retryWrites=false
关闭即可.详细可见
docs.mongodb.com/manual/core…
错误表因:
Cannot construct instance of com.*.*.domain.entity.app.AbstractCompositeContentApplicationEntity
(no Creators,
like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer,
or contain additional type information
jackson json转换更为严格,使用fastjson强制转换即可
错误表因:
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance
of com.*.*.domain.proto.in.ForwardCmdProto
(no Creators, like default constructor, exist): cannot deserialize
from Object value (no delegate- or property-based Creator)
lombok的改动导致的,使用lombok的配置文件改正这个错误.
https://github.com/projectlombok/lombok/issues/1563
org.springframework.data.mapping.MappingException: No property operator found on entity class
com.shanda.npc.lab.domain.entity.usage.UsageRecord to bind constructor parameter to!
在于没有生成一个spring初始化bean会用到的空构造函数.
升级了sring boot版本之后,连带着lombok的版本也升级了,新版本中默认不再为@Date和@Value注解的类生成private的空构造方法
解决办法一:
降级到支持生成空构造函数的版本.
projectlombok.org/changelog
但是从changelog来看,1.16.22默认是打开,但从此之后的版本就默认关闭了.可能官方并不推荐这样操作吧.
此方法还有个缺点就是随着jdk的升级,这个版本的lombok后面也没法再使用,只能采用方法二解决.
鉴于我自己使用方法二并未成功,所以采用了此办法.
使用lombok的config文件来开启某些特性.
java -jar lombok.jar config -g --verbose
在.m2文件夹下找到使用版本的lombok的jar,使用这个命令可以输出所有支持的config
在项目的根目录下新建lombok.config,将配置写入,即可.
lombok.noArgsConstructor.extraPrivate = true
随后可在target文件夹中查看编译好的class文件启用选项是否生效.
解决办法三:
使用lombok添加@NoArgsConstructor注解为实体类添加无参构造去除spring data 无法实例化的错误.
缺点是需要每个添加,巨多.而且要求后面新加的类也必须这样加
旧的配置文件更新
从以下配置
spring:
application:
name: file
servlet:
multipart:
max-file-size: 100Mb
max-request-size: 100Mb
spring:
application:
name: file
servlet:
multipart:
max-file-size: 104857600
max-request-size: 104857600
序列化问题
在pom中指定某些组件的版本号,如果当前pom的parent是spring,那么可以使用properties指定spring中管理的依赖版本号.
<properties>
<jackson-bom.version>2.12.1</jackson-bom.version>
</properties>
其中jackson在较新版本spring中使用jackson-bom指定,具体如何使用,可以查看spring的dependency中具体如何使用的
jackson将Object类型转换为·抽象类的实例·出错,使用fastjson强转.
com.*.*.core.component.ChatMessageResolver
AbstractCompositeContentApplicationEntity appAbstractInfo=new JacksonUtils().convertValue(msg.getExtend(),new TypeReference<>(){});
复制代码