According to the documentation and my observation an @EventListener annotated method is not opened by the spring plugin. Only if I open it manually, code is working. Otherwise there are these strange runtime errors with Spring AOP/CGLIB. Should the kotlin spring gradle plugin also open methods with @EventListener?
What’s your opinion?
By ‘open’, do you mean call/run/execute?
Also, it might help to see ‘these strange runtime errors’, and maybe also (a minimal, reproducible example of) your code.
No, I dont mean call/run/execute. The plugin (All-open compiler plugin | Kotlin Documentation) changes kotlins code generation esp. for some spring features: Classes and some Spring annotated methods are no longer final but open.
It is important to understand what this plugin does. Then you understand what I mean with strang errors.
My issue is that besides the current supported spring annotations the @EventListener annotation should also be supported.
Ah, thanks, that makes more sense.
Yes, you’d expect the plug-in to make all relevant classes and methods open/non-final (as Spring can’t do its magic otherwise). Presumably you’re getting errors along the lines of ‘Cannot subclass final class’?
But I don’t think we can tell you very much here (especially without seeing the Kotlin code and Gradle config). Have you considered opening an issue on YouTrack?
Here comes the example code. The test fails and (hopefully) should show what I mean.
BTW There isn’t a compile error. It’s just a runtime error.
YouTrack? Maybe my assumption is wrong, that the plugin should do the work.
kotlin-spring-plugin-eventlistener.zip (68.0 KB)
Any news after supplying code and config?
any news?
I looked into this, and read the docs you linked. I think this is your problem:
If the class (or any of its superclasses) is annotated with
com.my.Annotation
, the class itself and all its members will become open.
In your code, Sub
is annotated with @Service
. This means that Sub
gets the class and all of its methods made open
. Additionally, if you had any subclasses of Sub
, they would also have the class and all methods made open
. HOWEVER, it doesn’t work backwards; just because you have Sub
annotated, the plugin doesn’t go back up the dependency tree and make Base
open. So since the Base
class isn’t annotated with anything, the plugin doesn’t make it open. Also very important to note that, from what I understand of the docs, the annotation HAS to be on the class, not methods.