在一次开发中遇到这么一个问题,和大家分享下:
背景:在本机开发环境下没有发现问题,在服务器上代码也能编译通过,但是在重启服务器的时候一直抛这个异常:
string "--" is not permitted within comments.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
... 93 more
Caused by: org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [persistence/sqlmap-config.xml]; nested exception is com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: org.xml.sax.SAXParseException: The string "--" is not permitted within comments.
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:342)
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.afterPropertiesSet(SqlMapClientFactoryBean.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 103 more
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: org.xml.sax.SAXParseException: The string "--" is not permitted within comments.
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:62)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:62)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:55)
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:339)
... 106 more
Caused by: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: org.xml.sax.SAXParseException: The string "--" is not permitted within comments.
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:123)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:84)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:60)
... 109 more
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: org.xml.sax.SAXParseException: The string "--" is not permitted within comments.
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:62)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapParser.parse(SqlMapParser.java:44)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$10.process(SqlMapConfigParser.java:257)
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)
... 113 more
Caused by: org.xml.sax.SAXParseException: The string "--" is not permitted within comments.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.scanComment(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanComment(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at com.ibatis.common.xml.NodeletParser.createDocument(NodeletParser.java:189)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:59)
... 116 more
查了好就,服务器重启了N次,定位到是Ibatis的一个sqlMap文件的注释引发的问题:
<!-- 图集和类目关系待审核临时表 --> 这个是之前的注释,把这个注释去掉就能启动成功,把注释改一下<!-- 图集和类目关系待审核临时表 -->改成这样,在--和汉字之间加上空格也能成功,最中定位到是解析这个注释的问题。这个应该是个编码问题,因为单数个中文或者字母加单数个中文的注释就必须加上上面那个空格,如果不是则没问题,由于时间仓促,先研究到这,也希望大家指教一下到底是什么原因引起的~