javascript
基于注释的Spring Security实战
一、準備工作
?
預準備的工具及軟件有:
1.?Eclipse?IDE:我使用Eclipse?JEE?3.7版,即eclipse-jee-indigo-SR2-win32-x86_64.zip
2.?JDK?7:我使用JDK?7u4版,即jdk-7u4-windows-x64.exe
3.?Spring?Framework:我使用Spring?Framework?3.1.2版,即spring-framework-3.1.2.RELEASE-with-docs.zip
4.?Spring?Security:我使用Spring?Security?3.1.2版,即spring-security-3.1.2.RELEASE-dist
5.?其它JAR包:jstl-1.2.jar,commons-logging-1.1.1.jar,cglib-nodep-2.2.jar
6.?Tomcat應用服務器:我使用Tomcat?7.0.29版,即apache-tomcat-7.0.29-windows-x64.zip
?
說明:
1.?Eclipse?IDE和JDK?7的版本可以更高一些,不影響開發和調試。
2.?Eclipse一定要下載JEE版。
3.?Eclipse、JDK和Tomcat的安裝過程省略。
4.?我的操作系統是64位版本,故開發環境對應的工具都是下載64位的安裝包。
?
二、新建項目
在Eclipse環境下新建Dynamic?Web?Project。
項目名為:SpringSecurityDemo,
Target?runtime選擇New?Runtime,然后選擇Apache?Tomcat?v7.0,并設置好Tomcat的安裝目錄。
連續點擊兩次Next,在“Generate?web.xml?deployment?descriptor”處打勾選擇,并點擊Finish。
?
三、添加庫文件
把下列JAR文件添加到項目的WebContent\WEB-INF\lib目錄下。
四、業務層開發
1.?在項目src處,新建com.ch.configuration包,并新建WebConfig.java類,內容如下:
2.?新建com.ch.configuration.controller包,并新建MyController.java類,內容如下:
?
?
3.?新建com.ch.configuration.service包,并新建MyService.java接口類,內容如下:
4.?在com.ch.configuration.service包新建MyServiceImpl.java類,內容如下:
5.?在com.ch.configuration.service包新建MyServicesConfiguration.java類,內容如下:
package com.ch.configuration.service; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class MyServicesConfiguration { private MyService myService = new MyServiceImpl(); @Bean public MyService getMyService() { return myService; } }?
五、前臺頁面層開發
1.?在WebContent\WEB-INF目錄新建pages文件夾,接著在pages目錄下新建getTime.jsp文件,內容如下:
2.?在pages目錄下新建index.jsp文件,內容如下:
3.?修改WEB-INF下的web.xml文件,內容如下:
4.?在WEB-INF下新建MyServlet-security.xml文件,內容如下:
至此,Demo項目的開發已經完成。項目的整體結構圖如圖所示:
?
六、部署和運行
?
1.?在Eclipse選擇項目SpringSecurityDemo,右鍵選擇“Run?As”,再選擇“Run?on?Server”,選擇Apache?Tomcat?v7.0,Eclipse?IDE自動完成部署并運行。
在瀏覽器上輸入地址:http://localhost:8080/SpringSecurityDemo/
顯示如下:
注:地址自動被重定向到http://localhost:8080/SpringSecurityDemo/spring_security_login
User/Password輸入guest/guest,顯示:
如果輸入錯誤,顯示:
OK!本文就到這里,對于Spring的注釋,可以參考官方文檔加以理解。
轉載于:https://www.cnblogs.com/jokerjason/p/6000176.html
總結
以上是生活随笔為你收集整理的基于注释的Spring Security实战的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 让pt-slave-restart支持M
- 下一篇: Mysql基于GTIDs的复制