【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(前言)

  一直希望能够搭建一个完整的,基础Web框架,方便日后接一些外快的时候,能够省时省力,终于花了一周的时间,把这个东西搞定了。特此写下此博客,一来是纪念,二来是希望能够为别人提供方便。顺带说一下,恩,组合框架的各个部分用的版本有的是最新的,有的则不是,不敢保证最新版本下,按照这个整合方式,不会报错...

简单介绍一下,本框架的基本功能点:


  1. Spring:整个框架的主体部分,这个自不用说。
  2. SpringMVC:MVC部分我还是比较喜欢Spring的。
  3. MyBatis:选型的时候选择这个ORM主要也是考虑其灵活性的问题,毕竟我也不知道,今后会遇到怎样的需求,用Hibernate一来是不太会用,二来,我还是比较喜欢直接写SQL来的简单一点。
  4. SpringSecurity:这个主要是安全框架,负责用户登录验证及整站权限分配的相关事项(权限分配真的很有用,这个我就不多说了)。
  5. EhCache:一个非常流行又非常简单好用的缓存框架,并且目前已经支持分布式,如果觉得不好用,自己换成Redis也都OK。
  6. JCaptcha:一个简单的验证码生成框架(或者说工具)。
  7. Log4J:现在没人不知道这个日志框架吧...

  按照这样的选型,基本可以完成大部分网站的基础框架,如:

    1. 用户登录管理,
    2. 整站权限分配,
    3. 数据缓存,
    4. 登录验证码,
    5. 数据库操作,
    6. 统一异常处理,
    7. 日志输出。

  网上找了很多文章,大部分都是只有部分整合的,比如SSH整合,SSM整合,SpringMVC+SpringSecurity,等等,东一块,西一块,非常分散,而且每个人的配置方式还不一样,不统一,有的人喜欢注解配置,有的人喜欢XML配置,有的文章甚至直接就是有东没西,神龙见首不见尾。看的我是很郁闷,很蛋疼,因为当我好不容易搭好一个SSM框架,我发现,我要管理用户登录及权限分配的时候,咦,我还得去配置Security,然后又要找很多文章来补充知识,配置Security的时候,又要找验证码的框架,都搞好了以后,发现诶,缓存这个东西不都是任何一个网站必备的吗?所以就有了现在这篇文章,花了好大得劲,终于把所有都整合起来了。

但是,本文章,不提供项目源码!

只有自己亲手走过一遍,才真正学得会知识。作为一个程序员,我相信这样才是对我们是最好的一个方式。所以不要索要源码,不会给的。 先给出整个项目的

Pom.xml


  1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3     <modelVersion>4.0.0</modelVersion>
  4     <groupId>com.magic.rent</groupId>
  5     <artifactId>ssm</artifactId>
  6     <packaging>war</packaging>
  7     <version>1.0-SNAPSHOT</version>
  8     <name>ssm Maven Webapp</name>
  9     <url>http://maven.apache.org</url>
 10     <repositories>
 11         <repository>
 12             <id>atlassian</id>
 13             <name>atlassian</name>
 14             <url>http://maven.jahia.org/maven2/</url>
 15         </repository>
 16     </repositories>
 17     <build>
 18         <finalName>ssm</finalName>
 19         <plugins>
 20             <!--Mybatis 逆向工程插件-->
 21             <plugin>
 22                 <groupId>org.mybatis.generator</groupId>
 23                 <artifactId>mybatis-generator-maven-plugin</artifactId>
 24                 <version>1.3.2</version>
 25                 <configuration>
 26                     <verbose>true</verbose>
 27                     <overwrite>true</overwrite>
 28                 </configuration>
 29             </plugin>
 30         </plugins>
 31     </build>
 32     <properties>
 33         <security.version>4.1.3.RELEASE</security.version>
 34         <spring.version>4.3.3.RELEASE</spring.version>
 35     </properties>
 36     <dependencies>
 37         <!-- SpringFramework Start -->
 38         <dependency>
 39             <groupId>org.springframework</groupId>
 40             <artifactId>spring-core</artifactId>
 41             <version>${spring.version}</version>
 42         </dependency>
 43
 44         <dependency>
 45             <groupId>org.springframework</groupId>
 46             <artifactId>spring-web</artifactId>
 47             <version>${spring.version}</version>
 48         </dependency>
 49
 50         <dependency>
 51             <groupId>org.springframework</groupId>
 52             <artifactId>spring-oxm</artifactId>
 53             <version>${spring.version}</version>
 54         </dependency>
 55
 56         <dependency>
 57             <groupId>org.springframework</groupId>
 58             <artifactId>spring-tx</artifactId>
 59             <version>${spring.version}</version>
 60         </dependency>
 61
 62         <dependency>
 63             <groupId>org.springframework</groupId>
 64             <artifactId>spring-jdbc</artifactId>
 65             <version>${spring.version}</version>
 66         </dependency>
 67
 68         <dependency>
 69             <groupId>org.springframework</groupId>
 70             <artifactId>spring-webmvc</artifactId>
 71             <version>${spring.version}</version>
 72         </dependency>
 73
 74         <dependency>
 75             <groupId>org.springframework</groupId>
 76             <artifactId>spring-aop</artifactId>
 77             <version>${spring.version}</version>
 78         </dependency>
 79
 80         <dependency>
 81             <groupId>org.springframework</groupId>
 82             <artifactId>spring-context-support</artifactId>
 83             <version>${spring.version}</version>
 84         </dependency>
 85
 86         <dependency>
 87             <groupId>org.springframework</groupId>
 88             <artifactId>spring-test</artifactId>
 89             <version>${spring.version}</version>
 90         </dependency>
 91
 92         <dependency>
 93             <groupId>org.springframework</groupId>
 94             <artifactId>spring-expression</artifactId>
 95             <version>${spring.version}</version>
 96         </dependency>
 97         <!-- SpringFramework End -->
 98
 99         <!--SpringSecurity Start-->
100         <dependency>
101             <groupId>org.springframework.security</groupId>
102             <artifactId>spring-security-core</artifactId>
103             <version>${security.version}</version>
104         </dependency>
105         <dependency>
106             <groupId>org.springframework.security</groupId>
107             <artifactId>spring-security-web</artifactId>
108             <version>${security.version}</version>
109         </dependency>
110         <dependency>
111             <groupId>org.springframework.security</groupId>
112             <artifactId>spring-security-config</artifactId>
113             <version>${security.version}</version>
114         </dependency>
115         <dependency>
116             <groupId>org.springframework.security</groupId>
117             <artifactId>spring-security-taglibs</artifactId>
118             <version>${security.version}</version>
119         </dependency>
120         <dependency>
121             <groupId>org.springframework.security</groupId>
122             <artifactId>spring-security-crypto</artifactId>
123             <version>${security.version}</version>
124         </dependency>
125         <!--SpringSecurity End-->
126
127         <!--aspectj start-->
128         <dependency>
129             <groupId>org.aspectj</groupId>
130             <artifactId>aspectjweaver</artifactId>
131             <version>1.8.6</version>
132         </dependency>
133
134         <dependency>
135             <groupId>org.aspectj</groupId>
136             <artifactId>aspectjrt</artifactId>
137             <version>1.8.6</version>
138         </dependency>
139         <!--aspectj end-->
140
141         <!--c3p0-->
142         <dependency>
143             <groupId>com.mchange</groupId>
144             <artifactId>c3p0</artifactId>
145             <version>0.9.5.1</version>
146         </dependency>
147
148         <!--servlet/jsp api start-->
149         <dependency>
150             <groupId>javax.servlet</groupId>
151             <artifactId>servlet-api</artifactId>
152             <version>2.5</version>
153         </dependency>
154
155         <dependency>
156             <groupId>javax.servlet.jsp</groupId>
157             <artifactId>jsp-api</artifactId>
158             <version>2.1</version>
159             <scope>provided</scope>
160         </dependency>
161         <!--servlet/jsp api end-->
162
163         <!--junit4-->
164         <dependency>
165             <groupId>junit</groupId>
166             <artifactId>junit</artifactId>
167             <version>4.11</version>
168             <scope>test</scope>
169         </dependency>
170
171         <!--Mybatis-->
172         <dependency>
173             <groupId>org.mybatis</groupId>
174             <artifactId>mybatis</artifactId>
175             <version>3.3.0</version>
176         </dependency>
177         <!--Mybatis Spring整合-->
178         <dependency>
179             <groupId>org.mybatis</groupId>
180             <artifactId>mybatis-spring</artifactId>
181             <version>1.2.3</version>
182         </dependency>
183
184         <!--MySQL Driver-->
185         <dependency>
186             <groupId>mysql</groupId>
187             <artifactId>mysql-connector-java</artifactId>
188             <version>5.1.6</version>
189         </dependency>
190
191         <dependency>
192             <groupId>jstl</groupId>
193             <artifactId>jstl</artifactId>
194             <version>1.2</version>
195         </dependency>
196
197         <!--JCaptcha验证码-->
198         <dependency>
199             <groupId>com.octo.captcha</groupId>
200             <artifactId>jcaptcha</artifactId>
201             <version>1.0</version>
202         </dependency>
203
204         <!--公共工具包-->
205         <dependency>
206             <groupId>org.apache.commons</groupId>
207             <artifactId>commons-lang3</artifactId>
208             <version>3.4</version>
209         </dependency>
210
211         <!--Ehcache缓存框架 start-->
212         <dependency>
213             <groupId>net.sf.ehcache</groupId>
214             <artifactId>ehcache-core</artifactId>
215             <version>2.6.11</version>
216         </dependency>
217         <!--Mybatis-Ehcache整合包-->
218         <dependency>
219             <groupId>org.mybatis</groupId>
220             <artifactId>mybatis-ehcache</artifactId>
221             <version>1.0.0</version>
222         </dependency>
223         <!--Ehcache-Web页面及对象缓存-->
224         <dependency>
225             <groupId>net.sf.ehcache</groupId>
226             <artifactId>ehcache-web</artifactId>
227             <version>2.0.4</version>
228         </dependency>
229         <dependency>
230             <groupId>org.slf4j</groupId>
231             <artifactId>slf4j-api</artifactId>
232             <version>1.6.1</version>
233         </dependency>
234         <dependency>
235             <groupId>org.slf4j</groupId>
236             <artifactId>slf4j-log4j12</artifactId>
237             <version>1.6.2</version>
238         </dependency>
239         <!--Ehcache缓存框架 end-->
240     </dependencies>
241 </project>

项目结构截图



[图是高清的,我从1080P的屏幕下截取的]

[字太小可以下载到本地后放大,可以看得很清楚,亲测]

[回头有空,我再补一个目录结构文档]

时间: 2024-08-04 19:25:55

【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(前言)的相关文章

【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(三)

Spring+SpringMVC MVC呢,现在似乎越来越流行使用SpringMVC框架,我自己用的感觉,是非常好,确实很舒服,配置一开始是麻烦了一点点,但是后续的开发真的是很清爽! SpringMVC配置文件 目录:resource/config/spring,文件名:spring-mvc.xml 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.sp

【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(一)

Spring+MyBatis 首先要搭建的是Spring+MyBatis的整合框架,毕竟Spring是整个Web框架的核心部位,而数据库操作是一切测试的基础嘛. 目录结构 ━java ┣ controller(控制层) ┣ mapper(因为没有Dao,用Mapper层替代持久层) ┣ pojo(基础模型层) ┣ service(业务层) ┗ util(通用工具) ━resource ┣config ┣mybatis(MyBatis配置,其实这里的配置文件啥内容也没有) ┣spring(Spri

【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(四)

SpringSecurity(1) 其实啊,这部分我是最不想写的,因为最麻烦的也是这部分,真的是非常非常的麻烦.关于SpringSecurity的配置,让我折腾了好半天,网上的配置方式一大把,但总有一些功能不完全,版本不是最新等等的问题在,所以几乎没有一个教程,是可以整个贯通的.当然我的意思不是说那些不好,那些也不错,但就对于我来说,还不够全面.另外,SpringSecurity的替代品是shiro,据说,两者的区别在于,前者涵盖的范围更广,但前者也相对学习成本更高.又因为SpringSecur

【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(二)

Log4j 这个东西,大家都熟悉,就简单的介绍一下,算是一个抛砖引玉,因为我自己在Log日志的搭建方面,没有什么经验,但这东西确实是非常重要的,日后调Bug没有它基本不可能,如果有朋友有什么比较好的Log日志使用教程,还望可以告知一下. Log4j配置文件 目录:Resource,文件名:log4j.properties 新建一个log4j的配置文件,这个文件放在resource根目录下即可,貌似说是,项目启动的时候,会被自动加载,这个我就不懂了,因为我确实没有研究Log4j,只是网上看过几篇文

【JavaWeb】SSM+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(六)

Showings 我个人的项目,当前不断地在更新. 我希望做成一个好项目,同时,也是在锻炼自己的技术. 在项目中发现问题,学习知识,是比较可取的一条路子. 这样学习到的知识,虽然分散,但是都很实用,而且能够极大的加深程序设计与现实需求之间的关联. 网站地址:www.showings.com.cn Github源码[不断更新中]:https://github.com/wuxinzhe/HouseRent.git 这不算是一个多有技术含量的项目,我会不断在更新这个SAAS系统的功能,不断在完善业务逻

javaweb项目-医者天下 (Spring+SpringMVC+MyBatis)

项目下载地址:http://download.csdn.net/detail/qq_33599520/9826683 项目完整结构图: 项目简介: 医者天下项目是一个基于Spring+SpringMVC+MyBatis的javaweb项目,采用的是Mysql作为数据库,内部结构主要为注解方式,代码详细配有注释,项目完整度百分之95以上,有些小瑕疵未能处理,所以,此代码仅供参考使用,产生的任何漏洞和我无关. 项目代码贴出的顺序严格按照我搭建项目的顺序贴出代码,以保证代码的完整性和可用性. 项目结构

基于Spring+SpringMVC+Mybatis的Web系统搭建

主要的后端架构:Spring+SpringMVC+Mybatis+Shiro+Maven  IDE:IntelliJ IDEA 15.0.2 jdk:1.8.0_66 系统完整源码 https://github.com/Wellat/Factor 系统目录结构 跑起来效果 搭建步骤 1.用Idea创建maven项目 2.配置pom.xml文件,添加依赖 1 <?xml version="1.0" encoding="UTF-8"?> 2 <proj

SSM框架 (Spring+SpringMVC+MyBatis)

SSM框架--详细整合教程(Spring+SpringMVC+MyBatis) springspringmvcmybatis整合教程ssm整合 1.基本概念  1.1.Spring          Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Development and Design中阐述的部分理念和原型衍生而来.它是为了解决企业应用开发的复杂性而创建的.Spri

Spring+SpringMVC+Mybatis+Mysql整合实例【转】

本文要实现Spring+SpringMVC+Mybatis+Mysql的一个整合,实现了SpringMVC控制访问的页面,将得到的页面参数传递给Spring中的Mybatis的bean类,然后查找Mysql数据的功能,并通过JSP显示出来.建议可以先看笔者另一文章Mybatis与Spring整合创建Web项目 .笔者觉得整合过程中问题比较多的还是Spring+Mybatis的整合,SpringMVC的整合还是比较简单. Spring        Spring 是一个开源框架, Spring 是