All Projects → iquanzhan → SecKillShop

iquanzhan / SecKillShop

Licence: MIT license
🚀基于MyBatis、SpringBoot、Redis、消息队列的高并发处理的商品秒杀项目

Programming Languages

java
68154 projects - #9 most used programming language
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to SecKillShop

Blog Ssm
一个简单漂亮的SSM博客系统。
Stars: ✭ 130 (+420%)
Mutual labels:  thymeleaf, mybatis
My Blog
🌴A simple & beautiful blogging system implemented with spring-boot & thymeleaf & mybatis My Blog 是由 SpringBoot + Mybatis + Thymeleaf 等技术实现的 Java 博客系统,页面美观、功能齐全、部署简单及完善的代码,一定会给使用者无与伦比的体验
Stars: ✭ 2,400 (+9500%)
Mutual labels:  thymeleaf, mybatis
Sns Forum Website
牛客网高级项目(SNS+社区问答类网站)
Stars: ✭ 143 (+472%)
Mutual labels:  thymeleaf, mybatis
Autumn
Autumn-Blog and Autumn-CMS
Stars: ✭ 101 (+304%)
Mutual labels:  thymeleaf, mybatis
springboot-action
Spring Boot 入门学习示例。
Stars: ✭ 29 (+16%)
Mutual labels:  thymeleaf, mybatis
Nimrod
Nimrod - 基于 Spring Boot 构建 的 Java Web 平台企业级单体应用快速开发框架,适合中小型项目的应用和开发。所采用的技术栈包括 Spring Boot、Spring、Spring Web MVC、MyBatis、Thymeleaf 等,遵守阿里巴巴 Java 开发规约,帮助养成良好的编码习惯。整体采用 RBAC ( Role-Based Access Control ,基于角色的访问控制),具有严格的权限控制模块,支持系统与模块分离开发。最后希望这个项目能够对你有所帮助。Nimrod 开发交流群:547252502(QQ 群)
Stars: ✭ 125 (+400%)
Mutual labels:  thymeleaf, mybatis
Spring Boot Leaning
Spring Boot 2.X 最全课程代码
Stars: ✭ 2,008 (+7932%)
Mutual labels:  thymeleaf, mybatis
Maintain
springboot + springmvc +Spring Security + mybatis + PageHelper(Mybatis分页插件) + druid + (maven/gradle) + thymeleaf + bootstrap 组成的框架,基于Jersey, Swagger,SwaggerUi的restful API
Stars: ✭ 74 (+196%)
Mutual labels:  thymeleaf, mybatis
blog-ssm
一个简单漂亮的SSM博客系统。
Stars: ✭ 487 (+1848%)
Mutual labels:  thymeleaf, mybatis
Springboot Examples
spring boot 实践系列
Stars: ✭ 216 (+764%)
Mutual labels:  thymeleaf, mybatis
Blog
基于SpringBoot+Thymeleaf+Mybatis+LayUi+Lucene的粗糙个人博客
Stars: ✭ 95 (+280%)
Mutual labels:  thymeleaf, mybatis
t-blog
简洁的个人博客系统 springboot+thymeleaf+mybatis+tale.js+redis
Stars: ✭ 22 (-12%)
Mutual labels:  thymeleaf, mybatis
Jeeplatform
一款企业信息化开发基础平台,拟集成OA(办公自动化)、CMS(内容管理系统)等企业系统的通用业务功能 JeePlatform项目是一款以SpringBoot为核心框架,集ORM框架Mybatis,Web层框架SpringMVC和多种开源组件框架而成的一款通用基础平台,代码已经捐赠给开源中国社区
Stars: ✭ 1,285 (+5040%)
Mutual labels:  thymeleaf, mybatis
Ruoyi Oracle
(RuoYi)官方仓库 基于SpringBoot的权限管理系统 易读易懂、界面简洁美观。 核心技术采用Spring、MyBatis、Shiro没有任何其它重度依赖。直接运行即可用
Stars: ✭ 134 (+436%)
Mutual labels:  thymeleaf, mybatis
Mybatis Spring Boot Jpetstore
A sample web application built on MyBatis 3, Spring Boot and Thymeleaf 3.
Stars: ✭ 75 (+200%)
Mutual labels:  thymeleaf, mybatis
Spring Boot Examples
个人学习 SpringBoot2.x 写的一些示例程序,目前正在持续更新中.....
Stars: ✭ 159 (+536%)
Mutual labels:  thymeleaf, mybatis
Eshop Soa
EShop基于Dubbo实现SOA服务化拆分,并基于RocketMQ解决了分布式事务(新版SpringBootSOASkeleton)
Stars: ✭ 65 (+160%)
Mutual labels:  thymeleaf, mybatis
Blog
SpringBoot + Mybatis + thymeleaf 搭建的个人博客 http://www.54tianzhisheng.cn/
Stars: ✭ 1,156 (+4524%)
Mutual labels:  thymeleaf, mybatis
My Blog Layui
layui 版本的 My-Blog : A simple & beautiful blogging system implemented with spring-boot & layui & thymeleaf & mybatis My Blog 是由 SpringBoot + Layui + Mybatis + Thymeleaf 等技术实现的 Java 博客系统,页面美观、功能齐全、部署简单及完善的代码,一定会给使用者无与伦比的体验
Stars: ✭ 204 (+716%)
Mutual labels:  thymeleaf, mybatis
waynboot-sso
基于SpringBoot,Shiro,Redis,Mybatis,SSO的多模块系统,包含了SSO单点登陆, 通用后台管理,NewBee-mall商城,每日一文等多个模块,支持Shiro与SSO模块的集成,易于上手,学习,二次开发。
Stars: ✭ 33 (+32%)
Mutual labels:  thymeleaf, mybatis

SecKillShop

主要实现一个商品秒杀的功能,梳理如何应对高并发的的技术的思路。

Twitter Twitter Twitter Twitter Twitter

所用技术

1.后端:SpringBoot、JSR303、MyBatis

2.前端:Thymeleaf、BootStrap、Jquery

3.中间件:RabbitMQ、Redis、Druid

项目搭建

1.搭建SpringBoot
1.添加maven
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
2.集成thymeleaf
    1.导入依赖
        <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

    2.添加配置项:
      spring.thymeleaf.cache=false
      spring.thymeleaf.content-type=text/html
      spring.thymeleaf.enabled=true
      spring.thymeleaf.encoding=UTF-8
      spring.thymeleaf.mode=HTML5
      spring.thymeleaf.prefix=classpath:/templates/
      spring.thymeleaf.suffix=.html

    3.添加thymeleaf模版
      <!DOCTYPE HTML>
      <html xmlns:th="http://www.thymeleaf.org">
      <head>
        <title>hello</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      </head>
      <body>
        <p th:text="'hello:'+${name}" ></p>
      </body>
      </html>
3.集成MyBatis
  1.添加依赖
    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>1.3.1</version>
    </dependency>
  2.添加配置
    # mybatis
    mybatis.type-aliases-package=com.chengxiaoxiao.seckillshop.domain
    mybatis.configuration.map-underscore-to-camel-case=true
    mybatis.configuration.default-fetch-size=100
    mybatis.configuration.default-statement-timeout=3000
    mybatis.mapperLocations = classpath:com/chengxiaoxiao/seckillshop/dao/*.xml
4.添加MySql和Druid
    1.添加依赖
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>druid</artifactId>
          <version>1.0.5</version>
        </dependency>
    2.添加配置
        spring.datasource.url=jdbc:mysql://localhost:3306/miaosha?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8
        spring.datasource.username=root
        spring.datasource.password=123456
        spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
        spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
        spring.datasource.filters=stat
        spring.datasource.maxActive=2
        spring.datasource.initialSize=1
        spring.datasource.maxWait=60000
        spring.datasource.minIdle=1
        spring.datasource.timeBetweenEvictionRunsMillis=60000
        spring.datasource.minEvictableIdleTimeMillis=300000
        spring.datasource.validationQuery=select 'x'
        spring.datasource.testWhileIdle=true
        spring.datasource.testOnBorrow=false
        spring.datasource.testOnReturn=false
        spring.datasource.poolPreparedStatements=true
        spring.datasource.maxOpenPreparedStatements=20
        logging.leve.com.chengxiaoxiao.seckillshop=debug
5.安装redis
    1.官网:https://redis.io/download
   2.解压安装:
      1.解压文件:tar -zxvf redis-5.0.0.tar.gz
      2.移动到安装目录:mv redis-5.0.0 /usr/local/redis
      3.编译一下:make -j 4
        编译依赖gcc,安装如下:
          1.yum  install  gcc
          2.验证是否安装成功:rpm -qa |grep gcc
      4.make install
      5.修改配置文件
        vi redis.config
          1.修改可访问IP:修改bind 127.0.0.1  为bind 0.0.0.0
          2.修改后台启用:daemonize yes
          3.添加密码:requirepass
      6.运行:redis-server ./redis.conf
      7.重启:redis-cli     shutdown save
      8.命令行登录:auth password
      9.修改redis为系统服务
        1.cd utils
        2.  ./install_server.sh
        
        config:  /usr/local/redis/redis.config
        log:	/usr/local/redis/redis.log
        data:	/usr/local/redis/data
      10.查看后台进程是否存在
        1.查看进程:ps -ef |grep redis
        2.端口是否在监听:netstat -lntp | grep 6379
    3.添加依赖
          <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
          </dependency>

          <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.38</version>
          </dependency>
    4.添加配置:
          #redis            
          redis.host=192.168.220.128
          redis.port=6379
          redis.timeout=3
          redis.password=123456
          redis.poolMaxTotal=10
          redis.poolMaxIdle=10
          redis.poolMaxWait=3
6.防火墙开启端口
  1. 获取zone名称:firewall-cmd --get-active-zones
  2. 执行防火墙开启端口:firewall-cmd --zone=public --add-port=6379/tcp --permanent
  3. 重启防火墙:firewall-cmd --reload
  4. 查看端口是否开启:firewall-cmd --query-port=6379/tcp
  5. 查看服务:chkconfig --list | grep redis
7.添加集成MD5加密
  1. 添加依赖:
<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.6</version>
</dependency>

2.调用方法:

DigestUtils.md5Hex(src);
8.添加JSR303校验
1.添加依赖
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>
2.Controller中Vo上添加注解@Valid
3.自定义注解

1.添加注解类实现方法,注解类模板:

@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {IsMobileValidator.class })
public @interface IsMobile {

    String message() default "手机号码格式错误";

    Class<?>[] groups() default { };

    Class<? extends Payload>[] payload() default { };

}

2.添加注解校验规则类

public class IsMobileValidator implements ConstraintValidator<IsMobile, String> {
    @Override
    public void initialize(IsMobile constraintAnnotation) {
        
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        return true;
    }
}

2.使用

Vo对应属性上增加注解,实现校验

9.优化登录成功后,需要多次获取Cookie

1.自定义类,继承自WebMvcConfigurerAdapter,并添加@Configuration注解,使用参数解析器,重写addArgumentResolvers方法,添加自定义的解析器

2.自定义参数解析器,实现HandlerMethodArgumentResolver接口,重写supportsParameter和resolveArgument。

3.这样就可以直接在参数中增加对应的user,直接获取值了

Jemter压力测试

1.官网:http://jmeter.apache.org/

2.下载地址http://jmeter.apache.org/download_jmeter.cgi

3.修改界面为中文:

    找到jmeter下的bin目录,打开jmeter.properties 文件
    第三十七行修改为
    language=zh_CN

3.基本步骤:

    1.添加线程组
    2.添加HTTP请求配置器:

SpringBoot 打war包

1.添加依赖

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

2.添加plugins

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

3.修改打包方式为war

<packaging>war</packaging>

4.mainApplication需要继承SpringBootServletInitializer,并重写configure方法

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(MainApplication.class);
}

5.项目根目录打包:mvn clean package 6.放tomcat目录下,启动(解决需要增加应用名) 1.可以把context设置为空 2.直接放到ROOT目录下

页面优化

一、页面缓存

把页面渲染好的页面缓存放入redis

实现代码:

1.SpringBoot 2.0写法

//取缓存
WebContext ctx = new WebContext(request, response, request.getServletContext(), request.getLocale(), model.asMap());
html = thymeleafViewResolver.getTemplateEngine().process("goodlist", ctx);
if (!StringUtils.isEmpty(html)) {
    redisService.set(GoodsKey.getGoodList, "", html);
}

2.SpringBoot 1.0写法

SpringWebContext context = new SpringWebContext(request,response,request.getServletContext(),request.getLocale(),model.asMap(),applicationContext);
String html = thymeleafViewResolver.getTemplateEngine().process("goods_list",context);

二、对象缓存

1.在Service中,取Dao的数据时,先取redis的数据,如果redis中没有才取数据库的数据。 当数据库数据修改时,自动修改redis的数据

三、页面静态化

1.vue,angular进行页面静态化,减少服务器请求

热部署问题:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

添加maven后,会自动添加热部署功能。但需要进行重新编译才可以实现更新

静态资源优化

1.JS/CSS压缩

2.多个CSS/JS合并,减少链接

集成RabbitMQ

1.安装erlong

​ 1.安装依赖:

yum install ncurses-devel

​ 2.下载erlang包,编译安装

​ 1)http://www.erlang.org/downloads

​ 2)

2.安装RabbitMQ

​ 1.下载地址:http://www.rabbitmq.com/install-generic-unix.html

​ 2.

错误记录

​ (1).报错 ​

    An attempt was made to call the method javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; but it does not exist. Its class, javax.servlet.ServletContext, is available from the following locations:

    jar:file:/Users/ac/.gradle/caches/modules-2/files-2.1/javax.servlet/servlet-api/2.4/3fc542fe8bb8164e8d3e840fe7403bc0518053c0/servlet-api-2.4.jar!/javax/servlet/ServletContext.class
    jar:file:/Users/ac/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/8.5.34/a038040d68a90397f95dd1e11b979fe364a5000f/tomcat-embed-core-8.5.34.jar!/javax/servlet/ServletContext.class
    
(2).解决:servlet-api版本太低,升级即可,
    1.下载tomcat.zip包(https://tomcat.apache.org/download-80.cgi),
    2.找到lib/servlet-api.jar,复制到java jdk目录下/jre/lib/ext下
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].