The fix for this appears to be marking the controller method as `open fun` instead of fun. As it is ...
g
The fix for this appears to be marking the controller method as
open fun
instead of fun. As it is a leaf class, I don't understand why this would be so. Any ideas?
d
I believe you need to make the functions open for Spring to be able to create proxies to them (similarly to classes as well) OR you could apply https://kotlinlang.org/docs/all-open-plugin.html#spring-support and remove the unnecessary
open
modifiers
g
Thank you! That was a heavy debugging situation with a friend. We found our fix, and you've explained it.
n
it seems as if you ported the code from java to kotlin i’d suggest to create the project with https://start.spring.io/ and then port the code?
g
Thanks. Not my project, but I'll pass it on.
👍 1
m
I’m the friend and owner of the aforementioned project. Thank you for the help in fixing the issue and understanding where I was going wrong.
The part I still don’t understand is now around “something something Kotlin and Spring, therefore Spring needs to subclass my controller classes and override its functions in order to perform validation”
Further, I wonder if there’s some way, somehow, to provide better error messages, or something (don’t really know what), when there’s validation in the class, but it’s not being applied.
d
afaik spring will run those validations through some aspect (or aspect like logic) which requires a proxy -> if your class is final or your method is final spring cannot create a proxy so it won't run the validation
thats why it needs the explicit
open
modifier (which is default in Java)
m
So does Spring do the same thing in Java (create an aspect/proxy/something), and the difference is the default behavior of classes being open/closed?
d
yep
m
Hmmm, ok.
So is there any ability to provide better messages to point people to a solution?
d
*thats why there is also an
allopen
compiler plugin that automatically marks springs beans as open to make the kotlin experience better and not require explicit
open
i'd imagine the final/open part should be defined somewhere on the spring docs but hard to say
if you don't mark spring beans open then I guess it fail at startup, similarly it will fail if you don't open up the functions creating beans
in your case it was a valid bean but since method wasn't open it could not be proxied so it worked as if validation was not there
m
Correct
d
unsure if those misconfigurations could be detected -> guess probably? I'd recommend to open up an issue against Spring