正确的方法为不可变的构造函数注入Kotlin类
用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属性是不可变的。
在这里Kotlin没有太多的经验,但我认为这一定是可以做到的
public class AuthorizationController @Inject constructor(private val facebookAuth: FacebookAuthorizationService) { ... }
- Kotlin春天类方面的启动
- kotlin中的数字是不可序列化的
- Kotlin与Spring DI:lateinit属性尚未初始化
- Spring Data JPA + Guice错误:使用@EnableTransactionManagement注解时,没有类型的主要bean定义
- Spring MVC控制器PathVariables上的Java bean验证
- Kotlin + SpringBoot 2.0.0-M4失败tu加载应用程序上下文(BeanCreationException)
- Spring Boot 2和Kotlin(带Maven)
- Neo4J存储库没有连线到处
- Spring Boot无法在IntelliJ中运行单个测试