最近,调试一web项目,由于人员流动或时间问题出现web项目开发中Java ibatis配置问题导致Myeclipse启动web项目失败。
Myeclipse中使用其自带的tomcat进行run指定的web工程报错,报错信息如下(出于保密及问题说明,报错信息我做了调整):
2016-12-17 12:09:06,915 [main] DEBUG [org.mybatis.spring.SqlSessionFactoryBean]-Parsed mapper file:
'file [C:\Users\Administrator\Workspaces\MyEclipse 8.5\.metadata\.me_tcat\webapps\******\WEB-INF\classes\mapper\AdminLogMapper.xml]'
2016-12-17 12:09:06,941 [main] DEBUG [org.mybatis.spring.SqlSessionFactoryBean]-Parsed mapper file:
'file [C:\Users\Administrator\Workspaces\MyEclipse 8.5\.metadata\.me_tcat\webapps\******\WEB-INF\classes\mapper\AdminMenuMapper.xml]'
2016-12-17 12:09:06,994 [main] INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory]-Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5ff916: defining beans [accountServiceImpl,
......
t_SettleDao]; root of factory hierarchy
2016-12-17 12:09:06,996 [main]
ERROR [org.springframework.web.context.ContextLoader]-
Context initialization failed org.springframework.beans.factory.
BeanCreationException:
Error creating bean with name ' accountServiceImpl ': Injection of resource dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'accountDao' defined in file
[C:\Users\Administrator\Workspaces\MyEclipse 8.5\.metadata\.me_tcat\webapps\******\WEB-INF\classes\com\******\dao\
AccountDao.class]:
Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException:
Failed to parse mapping resource:
'file[C:\Users\Administrator\Workspaces\MyEclipse 8.5\.metadata\.me_tcat\webapps\******\WEB-INF\classes\mapper\
AdminParaMapper.xml]';
nested
exception is org.apache.ibatis.builder.BuilderException:
Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Parsing error was found in mapping #{}. Check syntax #{property|(expression), var1=value1, var2=value2, ...} at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122)
......
at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.parseParameterMapping(SqlSourceBuilder.java:127)
... 76 more
2016-12-17 12:09:07 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2016-12-17 12:09:07 org.apache.catalina.core.StandardContext start
严重: Context [/******] startup failed due to previous errors
2016-12-17 12:09:07 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
2016-12-17 12:09:07 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2016-12-17 12:09:07 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2016-12-17 12:09:07 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/49 config=null
2016-12-17 12:09:07 org.apache.catalina.startup.Catalina start
信息: Server startup in 11672 ms
通过以上报错信息,分析得出项目配置文件
spring-mybatis.xml 中定义的bean名字为
accountServiceImpl 所依赖的bean名字为
accountDao 的xml配置文件
AdminParaMapper.xml 中有语法错误:
Parsing error was found in mapping #{}. Check syntax #{property|(expression), var1=value1, var2=value2, ...} ,导致accountDao的bean无法创建,
引起
accountServiceImpl 在 Injection资源accountDao的过程中失败,从而导致 sqlSessionFactory创建失败,web项目加载失败。
排查
AdminParaMapper.xml 文件,发下以下配置有问题(红色部分是源代码,我已经注释,绿色代码是改正后的代码):
<update id="updateReleaseByM_flag" parameterType="string">
<!-- update adminpara set paravalue=#{} --> update adminpara set paravalue=#{paraValue} 按照如上分析结果改正配置后,项目启动过程中不再报错得以成功加载。