Autowiring a non-primitive with spring annotations like
@Autowired
lateinit var metaDataService: MetaDataService
works.
But this doesn't work:
@Value("\${cacheTimeSeconds}")
lateinit var cacheTimeSeconds: Int
with an error:
lateinit modifier is not allowed for primitive types.
How to autowire primitve properties into kotlin classes?
Best Answer
You can also use the @Value annotation within the constructor:
This has the benefit that your variable is final and none-nullable. I also prefer constructor injection. It can make testing easier.