Java ibatis配置問題導致Myeclipse啟動web專案失敗

清風艾艾發表於2016-12-17
    最近,除錯一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}

    按照如上分析結果改正配置後,專案啟動過程中不再報錯得以成功載入。


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29357786/viewspace-2130858/,如需轉載,請註明出處,否則將追究法律責任。

相關文章