原諒連結:http://blog.csdn.net/abcd_d_/article/details/50478344
最近整理一個二手後台管理項目,整體大體可分為 : Springmvc + mybatis + tiles + easyui + security 這幾個模組,再用maven做管理。剛拿到手裡面東西實在太多,所以老大讓重新整一個,只挑出骨架。不可否認,架構整體規劃得還是很好的,尤其是前端介面用tiles+easyui ,開發很高效。其實,之前雖然聽說過security,但做過的項目都沒用過security,所以也算是一個新手。整合過程還是很燒腦的。
1、首先是springmvc部分,也是架構的最核心骨架部分。springmvc也是基於servlet架構完成的,所以我們都可以從web.xml入手,然後順藤摸瓜,整理出整個架構。web.xml中主要部分是放置spring的各種配置:
[java] view plain copy <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/appServlet/servlet-context.xml </param-value> </context-param>
和
[html] view plain copy <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
這兩部分指定了設定檔地址和web請求地址攔截規則。需要注意的是,然後設定檔裡就是常用的註解、資料來源、之類的,不一而足。
2、然後是security,本文實現了自訂的使用者資訊登入認證,主要部分:spring的security主要注意幾個地方:
1)web.xml中配置security必須的過濾器,注意名字必須是springSecurityFilterChain,這是內建的過濾器;然後將過濾規則設定為/*,表示對所有請求都攔截。
2) 關於security的設定檔必須在<context-param>中加入,因為ContextLoaderListener在載入的時候就會去載入security相關的東西,而此時springmvc(servlet)模組還沒有初始化。
二者配置如下:
[java] view plain copy <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/appServlet/servlet-context.xml </param-value> </context-param>