因爲畢設中作的是圖片搜索網站,選擇前端框用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:
- 更換了jar包版本(調低)調到了如今的版本,還好在升級版本的時候還能夠繼續使用。
- 由於context 配置redis.properities時報錯,因此我乾脆不用這個配置文件,直接寫死,成功解決問題。
整合好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就好了。