Intelij idea mapper/dao.xml 一直循环加载

启动项目的时候,mapper配置文件一直循环加载,项目也没有报错,一般是xml里sql语句有问题。

解决方法:

新建一个类,继承 org.mybatis.spring.SqlSessionFactoryBean 类,重载 buildSqlSessionFactory 方法,捕获 NestedIOException 异常,并打印异常

public class FxSqlSessionFactoryBean extends SqlSessionFactoryBean {

    @Override
    protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
        try {
            return super.buildSqlSessionFactory();
        } catch (NestedIOException e) {
            e.printStackTrace(); // XML 有错误时打印异常。
            throw new NestedIOException("Failed to parse mapping resource: '" , e);
        } finally {
            ErrorContext.instance().reset();
        }
    }
}

项目xm文件中,找

 <!-- 注册sqlSessionFactory -->
 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
        <property name="dataSource" ref="dynamicDataSource"/>
        <property name="mapperLocations">
            <list>
                <value>classpath:com/ishehui/dmstore/dao/sqlmap/*.xml</value>
            </list>
        </property>
 </bean>

改为之前写的类

    <!-- 注册sqlSessionFactory -->
    <!--<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">-->
    <bean id="sqlSessionFactory" class="com.ishehui.dmstore.interceptor.FxSqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
        <property name="dataSource" ref="dynamicDataSource"/>
        <property name="mapperLocations">
            <list>
                <value>classpath:com/ishehui/dmstore/dao/sqlmap/*.xml</value>
            </list>
        </property>
    </bean>

再运行就会报错,定位到哪个xml文件出错

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页