ssm整合 报错org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):xxx

1. Reason for error

Use MapperScannerConfigurer to scan the corresponding mapper interface and help me put the mapper into the spring container, but my mapper mapping file is not associated with the sessionFactory.

When loading the mybatis core configuration file,
the environment, data source, and mapper tags will be invalid, and the mapper mapping file cannot be loaded.

    <!-- 配置sessionFactory -->
    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!-- 加载 mybatis核心配置文件-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        
    </bean>
    
    <!-- 将mapper接口给spring容器管理 -->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.bitqian.dao"/>
    </bean>

2. Solve

Need to load the mapper file in SqlSessionFactoryBean

    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!-- 加载 mybatis核心配置文件-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>

        <!-- 加载mapper 映射文件-->
        <property name="mapperLocations" value="classpath:cn/bitqian/mapper/*"/>

    </bean>

3. Description

  • This is just my problem, the mapper mapping file is not loaded
  • I have been working on this file for a long time
  • The essence of this problem is that the method corresponding to the mapper interface cannot be found. The method in the mapper interface fails to map with the statement tag in the mapper configuration file. Pay attention to whether the mapper mapping file namespace is consistent with the full class name of the mapper interface, and the id in the statement is the interface Whether the method name is consistent, and whether the parameterType and method parameters, resultType/resultMap are consistent with the return value type!

Guess you like

Origin blog.csdn.net/qq_44783283/article/details/108617395