因为毕设中作的是图片搜索网站,选择前端框用SSH,由于之间接触过SSH框架,略有了解,但没有深究,如今在整合redis和mongodb的过程当中遇到不少错误,也是十分痛苦,只能经过百度和一步步尝试着解决问题。前端
首先,先把本身在整合过程当中用到包先放出来。java
一开始使用的是spring3.0.4,整合好redis后发现这个版本整合mongodb特别麻烦,并且网上的方案也特别少,参考这个两个建议https://blog.csdn.net/wangpeng047/article/details/7705793;https://blog.csdn.net/erliang20088/article/details/45789975;我选着升级spring版本。web
先看看我在整合redis时遇到的错误:redis
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0':
Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException;
nested PropertyAccessExceptions (1) are:PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'systemPropertiesModeName' threw exception; nested exception is org.springframework.core.ConstantException:
整合好redis后开始整合mongodb,这个花了很长时间,主要的是jar包版本不匹配是问题,并且我也不知道到底谁和谁不匹配,并且同一个错误,网上会有不少不一样的解答,所以解决问题还得根据状况本身摸索,经过此次经历,我总结,之后作项目,必需要提早总体规划好,要否则最后更换根基费时费力。遇到的主要的报错是;spring
Unexpected exception parsing XML document from class path resource [mongodb.xml];
nested exception is org.springframework.beans.FatalBeanException:
Invalid NamespaceHandler class [org.springframework.data.mongodb.repository.config.MongoRepositoryConfigNamespaceHandler] for namespace
[http://www.springframework.org/schema/data/mongo]:
problem with handler class file or dependent class; nested exception is java.lang.NoClassDefFoundError:
org/springframework/data/repository/config/RepositoryConfigurationExtension
这个错误NoClassDefFoundError通常是由于缺乏某个jar包致使的。mongodb
导入jar包后,报错以下:app
Error creating bean with name 'mongoTemplate' defined in class path resource [mongodb.xml]:
Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException:
Could not instantiate bean class [org.springframework.data.mongodb.core.MongoTemplate]:
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/objenesis/ObjenesisStd
能够看出这个错误和以前的错误很类似,没错,我就卡在这很长时间,这个错误是由于jar包的版本不对致使的,因而我尝试不少版本的jar包,结果不行,看到框架
https://blog.csdn.net/wangpeng047/article/details/7705793;https://blog.csdn.net/erliang20088/article/details/45789975这两人的博客后,我选择升级spring版本,升级的方法就是只是替换spring其余的不动,以前把hibernate的版本也换成了4发现又有其余错,因此干脆不升级hibernate了,结果还不错没报错。eclipse
这个过程可能会有这个错误:webapp
Failed to process JAR [jar:file:/C:/Users/xu/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/Pic_searcher/WEB-INF/lib/org.springframework.context-4.3.2.RELEASE.jar!/]
for TLD files
这个错误是由于在导入该jar包的过程当中产生的错误,多是因为jar包损坏,解决方案是从新导入正确的jar便可。
接下来有了前面经验,跟着网上提供的步骤整合,又遇到了这个错误,因此果断更换jar包,spring-data-mongoDB.jar的版本以前时1.10,换成1.8时就解决此错误。
这样就解决了大的困难,接下来,就简单了许多,长路漫漫,还得共同努力。
这个过程有一种不求甚解的感受,这样很差,但时间紧迫,还有不少东西要学,时间宝贵,你我共同珍惜。
纠正一个错误,这个错误是在次日重启编译器发现的,有的时候就是这样必须得从新启动一下。
错误是hibernate的缘由,仍是由于在升级spring替换包的时候形成的,上图截图中有一个spring-orm包,这个包整合第三方的orm实现,如hibernate,ibatis,jdo以及spring 的jpa实现,若是你在applicationContext.xml文件中找到"org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean",而后Ctrl+左键你会发现它来自于这个包中,因此解决方法是不替换这个包,改成原来的spring-orm.3.4就好了。