有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Spring:使用ibatis库中的Java映射器时出错。接口不是bean

我正在使用Java和Spring框架开发一个后端应用程序。 我从一个原型项目开始,然而,它在运行阶段会导致一些问题。 我有这个界面:

@Mapper
public interface MyInterface {

    public ReturnType1 method1(long myLong);

    @Select("SELECT * FROM myTab WHERE id = #{myLong}")
    public ReturnType2 method2(long myLong);

    ...
    ...
}

此接口使用ibatis库(classorg.apache.ibatis.annotations.Mapper); 在代码的其他地方,我有以下服务:

@Service
public class ExampleService {

    @Autowired
    private MyInterface myInterface;

    ...
}

其中@Service注释为org.springframework.stereotype.Service;。多亏了@Autowired,该服务使用了@Mapper作为注释的接口(如前所述)

但是,在运行阶段,我得到以下错误:

应用程序启动失败:字段myInterface需要类型为MyInterface的bean,但找不到该bean。注入点具有以下注释:@org.springframework.beans.factory.annotation.Autowired(required=true)。考虑在配置中定义一个类型为“^ {CD7}}”的bean。

为什么向我报告这个错误?我不熟悉ibatis库。。。在我的项目中,我的路径中有一个xml文件:myProject/src/main/resources/mybatis/FileMapper。xml和在应用程序中。属性文件我有这一行:

mybatis.mapper-locations=classpath*:mybatis/*Mapper.xml

在我看来,一切都配置正确。你能解释一下我在哪里以及为什么会犯这个错误吗


共 (0) 个答案