电商秒杀系统方案优化,高性能高并发实战(一):项目框架搭建
一:简介:
后端技术采用SpringBoot,JSR303和Mybatis来实现。
秒杀系统包括:分布式会话,商品列表页,商品详情页,订单详情页,系统压测,缓存优化,消息队列,接口安全。
学习这门课程可以学到 如何利用缓存,如何使用异步,如何编写优雅的代码。
二、项目搭建:
继承Thymeleaf,Result结果封装,mybatis+Druid集成;jedis集成+redis集成+通用缓存Key封装
三:代码实现
application.porperties配置文件
1.springboot.thymeleaf配置
#thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
2.mybatis druid redis配置
#mybatis
mybatis.type-aliases-package=com.example.domain.model
mybatis.configuration.default-fetch-size=100
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-statement-timeout=3000
mybaits.mapperLocation=classpath:com/immoc/miaosha/dao/*.xml
#druid
spring.datasource.url=jdbc:mysql://localhost:3306/miaosha?characterEncoding=utf-8&serverTimezone=UTC&useSSL=false
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=yxq111222
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.minldle=1
#redis
redis.host=localhost
redis.port=6379
redis.timeout=10
redis.password=123456
redis.poolMaxTotal=10
redis.poolMaxIdle=10
redis.poolMaxWait=3
需要引入以下依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.5</version>
</dependency>二、编写各层的代码,详细代码已贴到github上,可以去look:https://github.com/whisperqi/miaosha_idea.git
版权声明:本文为weixin_42057351原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。