Spring Transactional annotation make bean unusable


#1

I have Kotlin class

@Component
open class NewsRecordProcessor @Autowired constructor(private val newsChecker: NewsChecker,
private val originNewsController: OriginNewsRecordController,
private val directoryProcessor: DirectoryProcessor) {…}

In this case it’s ok.
But I need to start transaction at one method begining. And then I’m adding

@Transactional

It’s no metter where am I put it, before function declaration or before class declaration. As soon annotation is putted all autowired fields are null. This bean also autowired in another bean, but it seams constructor with parameters wasn’t call
or fields is set to another proxy class.

What can I do to fix it?


#2

Same problem over here. Just contacted the Spring Data project lead. The behaviour of @Transactional on Kotlin classes is a complete mystery for me. Anything you found out so far?


#3

It sounds like the project hasn’t been built using the “all open” (or related) compiler plugin.

See https://kotlinlang.org/docs/reference/compiler-plugins.html

You might try start.spring.io to create a starter project for reference?

HTH