使用Spring + Kotlin声明不可变构造函数注入类的正确方法是什么?目前我有:
@RestController
public class AuthorizationController
{
@Inject
lateinit var facebookAuth: FacebookAuthorizationService //Mutable?
@RequestMapping("/authorization")
public fun authorization(@RequestParam(value = "network-type", defaultValue = "Facebook") name: String,
@RequestParam(value = "oauth-token") oauthToken: String,
@RequestParam(value = "oauth-token-secret",
required = false) oauthTokenSecret: String?): Authorization
{
//TODO: Handle other network types
return facebookAuth.authorization(oauthToken)
}
}
我希望facebookAuth属性是不可变的。
答案 0 :(得分:3)
在这里对Kotlin的经验不多,但我认为必须用
完成public class AuthorizationController @Inject constructor(private val facebookAuth: FacebookAuthorizationService) {
...
}