小编Jac*_*Zhu的帖子

kotlin如何在多层应用函数中引用外部范围

例如:

 v1?.apply {
       v2?.apply {
           call(this, target, outerThis);
       }
    }
Run Code Online (Sandbox Code Playgroud)

我的问题是如何引用"outerThis"?谢谢你的帮助.

lambda apply kotlin

10
推荐指数
2
解决办法
2186
查看次数

Spring-data 2.1 使用 kotlin 获取“UnsupportedOperationException: No accessor to set property”

环境:Spring-boot 2.1.2.RELEASE、Spring-data 2.1.4.RELEASE、Kotlin 1.2.x ~ 1.3.x、Mongodb。

我定义了一个模型类,如:

@Document
class MeAccount : Setting() {

    lateinit var id: String

    val accountEntries = listOf<BankAccount>()
 }
Run Code Online (Sandbox Code Playgroud)

当我试图从 mongodb 读取这个模型时,我得到了异常堆栈跟踪:

java.lang.UnsupportedOperationException: No accessor to set property private final java.util.List com.xxx.MeCustodianAccount.accountEntries!
    at com.xxx.MeCustodianAccount_Accessor_fs514j.setProperty(Unknown Source)
    at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:61)
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:378)
Run Code Online (Sandbox Code Playgroud)

请注意,该代码适用于 spring-boot 1.5.x 和 spring-data 1.x。

我能做些什么来解决这个问题?下面似乎有很多类似的异常报告:

Spring Boot 2.1.0 安全性更改与 kotlin 数据类?

https://github.com/arangodb/spring-data/issues/123

https://github.com/spring-projects/spring-boot/issues/15698

[已解决] 回退到 Spring-boot 2.0.x 和 spring-data-commons 2.0.x 后有效。将在未来的升级计划中排除 2.1。

mongodb spring-data kotlin spring-data-mongodb

6
推荐指数
1
解决办法
6753
查看次数