我的
Spring-Boot
和;
Couchbase
应用程序有一个
Cat
数据库中的对象。
在新的应用程序版本中,我们将新的布尔字段添加到
猫
文档对象:
@RequiredArgsConstructor
@AllArgsConstructor(onConstructor = @__(@PersistenceConstructor))
@Document
@Data
@Builder
@EqualsAndHashCode
public class Cat {
....
@Field
final boolean isHungry
但是现在,我们已经有了数据库中没有这个字段的cat对象。
当应用程序试图读取这些
Cats
我们得到这个错误:
org.springframework.data.mapping.model.MappingInstantiationException: Failed
to instantiate com.example.Cat using constructor public
com.example.Cat(...) with arguments ...
...
Caused by: java.lang.IllegalArgumentException: Parameter isHungry must not be null!
有没有办法告诉你
Spring
如果数据库中缺少该字段,则应使用默认值(
false
在这种情况下)