Is there a way in Spring 5.0 to autowire a functio...
# spring
c
Is there a way in Spring 5.0 to autowire a function somehow? I have this setup: in Java
Copy code
@Service
public class CommandService {
    public <C extends Command, R: Any> R execute(C command) {/*...*/}
}
in Kotlin I want to somehow be able to write
SomeCommand(/* properties */).execute()
Currently to achieve that in some of the code following approach is used: adding
private fun <R : Any> Command.execute(): R = commandService.execute(this)
to all of the client classes as well as an autowired
val commandService: CommandService
. I need to change that as this happens more often it's too much repetition. I've came up with the following, but it looks a bit hacky to me.
Copy code
fun <T : Any> Command.execute(): T = STATIC_COMMAND_SERVICE.execute(this)

private lateinit var STATIC_COMMAND_SERVICE: CommandService

@Configuration
class CommandServiceKotlinInitializer(commandService: CommandService) {
	init {
		STATIC_COMMAND_SERVICE = commandService
	}
}