今天修改了一些东西后,发现web项目启动不了了。日志中出现504组如下的日志,都是mybatis打印的,扫描jar,解析dao,mapping文件等信息。费了半天劲,也没有找到问题。因为这些全是debug级别的,我就没有在意。后来发现每组的最后一条信息"Ignoring bean creation exception...",有错误信息,才发现问题的根源是mybatis的mapping.xml文件中,语句的id重复了。
可问题是
1.为什么会打印这么多重复的日志呢?
2.为什么只有debug级别的日志呢?
问题1:
通过对日志 和源码的学习,终于把第一问题解答了。
1). dao类是需要注入一个SqlSessionFactory的。mybatis与spring整合,对应的是SqlSessionFactoryBean类。
2). SqlSessionFactoryBean在创建的时候,会加载所有的mapping文件。
3). 当加载失败的时候,不会抛出异常,只是打印了一个debug级别的日志。刚才提到的"Ignoring bean creation exception..."信息。
所以程序会继续进行。
4). 然后,当每次需要注入“依赖 [此SqlSessionFactoryBean类] 的Dao类”的时候,就会打印一组 3)中的错误信息。
so,当有很多类依赖这些Dao的时候,就有了这504组错误信息。。
问题2:
查看了所有的日志,发现只有这一行信息能够清楚的说明问题的原因。这一行信息是由spring记录的。( org.springframework.beans.factory.support.AbstractBeanFactory#getTypeForFactoryBean )
估计他并不想直接吞掉这个异常,因为把这个Exception放入了suppressedExceptions属性里,可能会在必要的时候统一抛出。
可是,在这种情况下,他并没有抛出正确的异常。不知算不算mybatis-spring的bug。总之,这种编程问题,在测试环境下,就可以发现,不会影响生产环境,所以问题也不大。不过这种处理方式,错信息混杂在debug级别的信息中,确实不太好定位问题。
附两组日志:
DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'tradeShareDao' DEBUG DefaultListableBeanFactory - Creating instance of bean 'tradeShareDao' DEBUG DefaultListableBeanFactory - Eagerly caching bean 'tradeShareDao' to allow for resolving potential circular references DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'settlementSqlSessionFactory' DEBUG DefaultListableBeanFactory - Creating instance of bean 'settlementSqlSessionFactory' DEBUG DefaultListableBeanFactory - Eagerly caching bean 'settlementSqlSessionFactory' to allow for resolving potential circular references DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'settlementDataSource' DEBUG PathMatchingResourcePatternResolver - Looking for matching resources in jar file [file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar] DEBUG PathMatchingResourcePatternResolver - Resolved location pattern [classpath:settlement_mapper/*Mapper.xml] to resources [class path resource [settlement_mapper/PaymentTypeMapper.xml], class path resource [settlement_mapper/TradeShareMapper.xml]] DEBUG DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'settlementSqlSessionFactory' DEBUG ResolverUtil - Find JAR URL: jar:file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar!/com/test/settlement/orm/ DEBUG ResolverUtil - Inner URL: file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar!/com/test/settlement/orm/ DEBUG ResolverUtil - Extracted JAR URL: file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar DEBUG ResolverUtil - Found JAR: file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar DEBUG ResolverUtil - Listing jar:file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar!/com/test/settlement/orm/ DEBUG ResolverUtil - Found resource: /com/test/settlement/orm/dao/TradeShareDao.class DEBUG ResolverUtil - Found resource: /com/test/settlement/orm/dao/PaymentTypeDao.class DEBUG ResolverUtil - Checking to see if class com.test.settlement.orm.dao.TradeShareDao matches criteria [is assignable to Object] DEBUG ResolverUtil - Checking to see if class com.test.settlement.orm.dao.PaymentTypeDao matches criteria [is assignable to Object] DEBUG DefaultListableBeanFactory - Ignoring bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tradeShareDao' defined in URL [jar:file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar!/com/test/settlement/orm/dao/TradeShareDao.class]: Cannot resolve reference to bean 'settlementSqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settlementSqlSessionFactory' defined in class path resource [applicationContext-db-settlement.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'class path resource [settlement_mapper/manual-SettleItemMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: XML fragments parsed from previous mappers already contains value for com.test.settlement.orm.dao.SettleItemDao.SettleItem_columns DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'paymentTypeDao' DEBUG DefaultListableBeanFactory - Creating instance of bean 'paymentTypeDao' DEBUG DefaultListableBeanFactory - Eagerly caching bean 'paymentTypeDao' to allow for resolving potential circular references DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'settlementSqlSessionFactory' DEBUG DefaultListableBeanFactory - Creating instance of bean 'settlementSqlSessionFactory' DEBUG DefaultListableBeanFactory - Eagerly caching bean 'settlementSqlSessionFactory' to allow for resolving potential circular references DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'settlementDataSource' DEBUG PathMatchingResourcePatternResolver - Looking for matching resources in jar file [file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar] DEBUG PathMatchingResourcePatternResolver - Resolved location pattern [classpath:settlement_mapper/*Mapper.xml] to resources [class path resource [settlement_mapper/PaymentTypeMapper.xml], class path resource [settlement_mapper/TradeShareMapper.xml]] DEBUG DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'settlementSqlSessionFactory' DEBUG ResolverUtil - Find JAR URL: jar:file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar!/com/test/settlement/orm/ DEBUG ResolverUtil - Inner URL: file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar!/com/test/settlement/orm/ DEBUG ResolverUtil - Extracted JAR URL: file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar DEBUG ResolverUtil - Found JAR: file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar DEBUG ResolverUtil - Listing jar:file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar!/com/test/settlement/orm/ DEBUG ResolverUtil - Found resource: /com/test/settlement/orm/dao/TradeShareDao.class DEBUG ResolverUtil - Found resource: /com/test/settlement/orm/dao/PaymentTypeDao.class DEBUG ResolverUtil - Checking to see if class com.test.settlement.orm.dao.TradeShareDao matches criteria [is assignable to Object] DEBUG ResolverUtil - Checking to see if class com.test.settlement.orm.dao.PaymentTypeDao matches criteria [is assignable to Object] DEBUG DefaultListableBeanFactory - Ignoring bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'paymentTypeDao' defined in URL [jar:file:/xxxx/webapps/management/WEB-INF/lib/xxx-settlement-orm-1.0-SNAPSHOT.jar!/com/test/settlement/orm/dao/PaymentTypeDao.class]: Cannot resolve reference to bean 'settlementSqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'settlementSqlSessionFactory' defined in class path resource [applicationContext-db-settlement.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'class path resource [settlement_mapper/manual-SettleItemMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: XML fragments parsed from previous mappers already contains value for com.test.settlement.orm.dao.SettleItemDao.SettleItem_columns
相关推荐
达内 MyBatis 核心_扫描版_2.42M
springboot,mybatis,springboot-mybatis环境,自动生成dao实现类,自动扫描 springboot环境,mybatis自动扫描,mybatis无需实现类,mybatis mapper扫描 springboot mybatis 手动写dao实现类的: ...
spring和mybatis框架整合,采用mapper代理自动扫描方式实现,已添加junit测试类。建议参照我的另一资源spring和mybatis整合(原始dao方式实现)对比
struts2+mybatis解决longblob字段问题,存读取并下载longblob字段
达内 Spring+MyBatis 开发实战_扫描版_2.42M
MyBatis中Foreach参数问题.doc
mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例...
mybatis源码是mybatis-3.2.6的源码,用户使用mybatis时可以进行参考
mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis练习3mybatis...
mybatis deom.mybatis 的简单入门实例。基于maven开发的。
这时如果使用jdbc继续使用之前的连接,则会收到以下异常:mysql允许设置闲置时间,默认是8小时,最大是1年。大部分客户端都使用连接池以提高性能,如果用户访问
Spring Boot+Mybatis Plus+Thymeleaf实现用户登录和校验用户名是否重复功能
开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2...
mybatis、mybatis详细设计、mybatis配置
mybatis-plus就很好的解决了这个问题。 MyBatisPlus是一个Mybatis的增强工具,在 Mybatis 的基础上只做增强不做改变,为简化开发、提高效率而生。它主要通过启动时自动注入基本CURD,达到简化操作的目的。 关于...
mybatis_plugin2.9.2
MyBatis学习代码: mybatis实战教程mybatis in action之一开发环境搭建 mybatis实战教程mybatis in action之二以接口的方式编程 mybatis实战教程mybatis in action之三实现数据的增删改查 mybatis实战教程mybatis in...
<sqlMapGenerator targetPackage="mybatis.mapper.sale.order" targetProject="pos-service/src/main/resources"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> ...
springmvc+spring4+mybatis3整合,自动扫描,内无示范,架构搭好,非maven项目