Spring Boot @Autowired with Kotlin in @Service is always null

后端 未结 3 1482
闹比i
闹比i 2021-02-19 00:21

Currently I try to rewrite my Java Spring Boot Application with Kotlin. I encountered a problem that in all of my classes which are annotated with @Service the depe

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-19 01:07

    Which Spring Boot version do you use? Since 1.4 Spring Boot is based on Spring Framework 4.3 and since then you should be able to use constructor injection without any @Autowired annotation at all. Have you tried that?

    It would look like this and works for me:

    @Service
    class UserServiceController(val dsl: DSLContext, val teamService: TeamService) {
    
      // your class members
    
    }
    

提交回复
热议问题