javakotlin&springboot我有一个MyBatis映射器,我正在“猴子补丁”一个方法,并且需要一个自动连接的bean
我在Kotlin中有一个接口,它是MyBatis映射器:
@Mapper
interface EquipmentSupportMapper {
// @Autowired lateinit var metaMapper: MetaMapper // <- Does not work... How?
@SelectProvider(type = SqlProviderAdapter::class, method = "select")
fun findMany(selectStatement: SelectStatementProvider?): List<Equipment>
}
然后,我在其中添加了一个方法实现:
fun EquipmentSupportMapper.searchEquipment(
textSearchValue: String? = null, facilities: Array<Int>? = null,
manufacturers: Array<Int>? = null, equipmentExample: Equipment? = null
):
List<Equipment> {
val builder = SqlBuilder.select(equipmentColumnList)
.from(EquipmentSupport.EquipmentTable)
.where()
...
return someList;
现在,在我的方法searchEquipment
中,我需要@Autowire
一个名为MetaMapper
的Springbean
我不能只是补充:
接口中的@Autowired lateinit var metaMapper: MetaMapper
,因为它会给出错误。我该怎么做
# 1 楼答案
事实证明我能做到:
诀窍是在Spring为其创建实现的接口上创建一个限定符,然后通过委托给自动连接的Spring创建的bean,将其注入实现同一接口的类中
然后,我没有在我的应用程序中使用名为IESM的
Mapper
,而是用限定符EquipmentSupportMapper自动连线,得到了正确的一个下面是一个测试示例: