在spring kotlin支持中指定默认autowireMode的方法

Spring引导版本2,Spring框架版本5。

如何为beans DSL指定默认的autowireMode ? 我目前使用这个每个bean:

 fun beans() = org.springframework.context.support.beans { bean(autowireMode = BeanDefinitionDsl.Autowire.BY_NAME) bean(autowireMode = BeanDefinitionDsl.Autowire.BY_NAME) // hundreds more bean } 

这是乏味的。 bean实现来自传统应用程序,所以我不能使用Component

只需编写自己的扩展方法:

 inline fun  BeanDefinitionDsl.beanByName(name: String? = null, scope: Scope? = null, isLazyInit: Boolean? = null, isPrimary: Boolean? = null isAutowireCandidate: Boolean? = null) { this.bean(name = name, scope = scope, isLazyInit = isLazyInit, isPrimary = isPrimary, isAutowireCandidate = isAutowireCandidate, autowireMode = Autowire.BY_NAME) } 

然后使用它

 fun beans() = org.springframework.context.support.beans { beanByName() beanByName() // hundreds more bean }