程序问答   发布时间:2022-05-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Kotlin & Spring Boot - 我有一个 MyBatis 映射器,我正在“猴子修补”一个方法,并且需要在该方法中使用一个自动装配的 bean大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Kotlin & Spring Boot - 我有一个 MyBatis 映射器,我正在“猴子修补”一个方法,并且需要在该方法中使用一个自动装配的 bean?

开发过程中遇到Kotlin & Spring Boot - 我有一个 MyBatis 映射器,我正在“猴子修补”一个方法,并且需要在该方法中使用一个自动装配的 bean的问题如何解决?下面主要结合日常开发的经验,给出你关于Kotlin & Spring Boot - 我有一个 MyBatis 映射器,我正在“猴子修补”一个方法,并且需要在该方法中使用一个自动装配的 bean的解决方法建议,希望对你解决Kotlin & Spring Boot - 我有一个 MyBatis 映射器,我正在“猴子修补”一个方法,并且需要在该方法中使用一个自动装配的 bean有所启发或帮助;

我在 Kotlin 中有一个接口,它是一个 MyBatis 映射器:

@H_675_5@@mapper
interface EquipmentSupportMapper {
    // @autowired lateinit var MetaMapper: MetaMapper // <- Does not work... How?
    @SELEctProvIDer(type = sqlProvIDerAdapter::class,method = "SELEct")
    fun findMany(SELEctStatement: SELEctStatementProvIDer?): List<Equipment>
}

然后我在其中添加一个方法实现:

@H_675_5@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;

现在,在我的方法 @H_675_5@searchEquipment 中,我需要 @H_675_5@@autowire 一个名为 @H_675_5@metaMapper 的 spring bean。

我不能只是添加:

@H_675_5@@autowired lateinit var MetaMapper: MetaMapper 在界面中,因为它给出了错误。我该怎么做?

解决方法

事实证明我可以做到这一点:

@H_675_5@@mapper
@Qualifier("IESM")
interfacE interfaceEquipmentSupportMapper {
    // @Autowired lateinit var metaMapper: MetaMapper // <- Does not work... How?
    @SELEctProvider(type = SqlProviderAdapter::class,method = "SELEct")
    fun findMany(SELEctStatement: SELEctStatementProvider?): List<Equipment>
}

@service
@Qualifier("EquipmentSupportMapper")
class EquipmentSupportMapper(
    @Autowired @Qualifier("IFSM") ifsm: InterfaceEquipmentSupportMapper,@Autowired metaMapper: MetaMapper
  ): InterfaceEquipmentSupportMapper by ifsm

诀窍是在 Spring 为其创建实现的接口上创建一个限定符,然后通过委托给自动装配的 Spring 创建的 bean 将其注入到实现相同接口的类中。

然后,我没有在我的应用中使用名为 IESM 的 @H_675_5@mapper,而是使用限定符 EquipmentSupportMapper 自动装配,然后我得到了正确的。 >

这是一个测试示例:

@H_675_5@@SpringBootTest
class EquipmentSupportMapperTest {
    @Autowired
    @Qualifier("EquipmentSupportMapper")
    lateinit var mapper: EquipmentSupportMapper

大佬总结

以上是大佬教程为你收集整理的Kotlin & Spring Boot - 我有一个 MyBatis 映射器,我正在“猴子修补”一个方法,并且需要在该方法中使用一个自动装配的 bean全部内容,希望文章能够帮你解决Kotlin & Spring Boot - 我有一个 MyBatis 映射器,我正在“猴子修补”一个方法,并且需要在该方法中使用一个自动装配的 bean所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。