How to use spring annotations like @Autowired in kotlin?

前端 未结 4 1072
孤城傲影
孤城傲影 2020-12-13 01:38

Is it possible to do something like following in Kotlin?

@Autowired
internal var mongoTemplate: MongoTemplate

@Autowired
internal var solrClient: SolrClient         


        
4条回答
  •  不知归路
    2020-12-13 02:05

    You can also autowire dependencies through the constructor. Remember to annotate your dependencies with @Configuration, @Component, @Service etc

    import org.springframework.stereotype.Component
    
    @Component
    class Foo (private val dependency: MyDependency) {
        //...
    }
    

提交回复
热议问题