在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 }
- Spring Boot无法在IntelliJ中运行单个测试
- Kotlin Spring Boot使用Map创建urlencoded POST请求
- 如何配置使用klaxon库的spring引导
- 使用kotlin-maven-plugin构建的jar中的Kotlin类
- IntelliJ Idea 2017.3无法启动Kotlin Spring Boot App – @Configuration类可能不是最终的
- 在springMVC 3,如何写一个cookie,同时返回一个ModelAndView?
- Spring Boot 2&Kotlin 1.2.1:过时的运行时间
- Spring WebFlux:只有一个连接接收用户允许
- 在Spring Boot项目中使用Gradle从Kotlin测试引用Java代码时未解决的参考