1. Spring MVC 雙請求問題html
viewresolver必定要放在servlet-dispatcher.xml裏,不然會致使在請求成功後之後渲染頁面,而後又發一次請求的情況,最後致使頁面沒法顯示.例如如下Controller方法java
@RequestMapping("loginPage") public String loginPage() { return "loginView"; }
會形成以下log輸出web
00:31:30.836 [http-bio-8080-exec-8] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'web' processing GET request for [/loginPage]
00:31:30.836 [http-bio-8080-exec-8] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /loginPage
00:31:30.836 [http-bio-8080-exec-8] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Returning handler method [public java.lang.String com.qunar.scoresystem.controller.LoginController.loginPage()]
00:31:30.836 [http-bio-8080-exec-8] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'loginController'
00:31:30.836 [http-bio-8080-exec-8] DEBUG o.s.web.servlet.DispatcherServlet - Last-Modified value for [/loginPage] is: -1
00:31:30.836 [http-bio-8080-exec-8] DEBUG o.s.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'loginView'; URL [loginView]] in DispatcherServlet with name 'web'
00:31:30.837 [http-bio-8080-exec-8] DEBUG o.s.web.servlet.view.JstlView - Forwarding to resource [loginView] in InternalResourceView 'loginView'
00:31:30.837 [http-bio-8080-exec-8] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'web' processing GET request for [/loginView]
00:31:30.837 [http-bio-8080-exec-8] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /loginView
00:31:30.837 [http-bio-8080-exec-8] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/loginView]
00:31:30.837 [http-bio-8080-exec-8] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/loginView] in DispatcherServlet with name 'web'
00:31:30.837 [http-bio-8080-exec-8] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
00:31:30.837 [http-bio-8080-exec-8] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed requestredis
最後發送了兩次http請求spring
2. Idea Web目錄建Module加載問題json
在idea中必需要將web目錄設爲"web"目錄, 就是在配置中要將其加入到Module中,加入後在web目錄圖標中會有一個小地球,不然裏面的資源會找不到,並且不會給你任何提示api
3. Spring從3.2版本開始默認使用URL後綴來判斷reponse類型, 例如對於@Responsebody來講,/test/list.json 則會返回content-type爲json的數據, 而/test/list.xml則會返回xml數據.這點對於寫rest api可能會有問題, 由於你期待返回json數據(accept頭爲application/json), 而url後綴叫別的(例如.htm),那麼程序就會自動將返回類型修改成application/html, 致使返回406(返回的數據類型與期待的accept類型對不上)瀏覽器
咱們能夠經過關閉自動根據url後綴判斷內容類型來修正這一點. spring-mvc
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" /> <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> <property name="favorPathExtension" value="false" /> <property name="favorParameter" value="false" /> </bean>
要注意的是此處 須要制定xsi:schemaLocation爲Spring3.2的doc,在XML文件首指定:緩存
xsi:schemaLocation="http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"
詳情請參見Spring doc
這樣能夠解決返回406的問題
另外說一句, 某項目的URL全都以htm結尾, 這是致使這個問題的緣由,並且這自己就是不正確的命名方法, 以htm結尾會致使全部頁面內容被瀏覽器緩存, 這樣html頁面修改後瀏覽器也只能強制刷新緩存才能顯示最新的頁面. 總之, 返回json的請求就不該該叫.htm, 而應該叫 .json. 或者說沒有後綴
4. Jedis 2.2 與 Spring-data-jedis 1.1.0-RELEASE 不兼容問題, 詳見
redis release a new version 2.2.0 and is not compatible with spring data redis. org.springframework.data.redis.connection.jedis.JedisConnection referred redis.clients.jedis.BinaryTransaction and this class has been removed.
5. 要注意自動spring配置文件中schema的聲明, idea補全常常出錯, 例如把mvc補全成cache