阿里3个小时手把手教你用zookeeper实现分布式锁( 二 )

工程的搭建

搭建ssm框架 有时间推出springboot的版本
  • 创建一个maven项目(普通maven项目即可)
创建数据库:sql
-- 商品表create table product(id int primary key auto_increment, -- 商品编号product_name varchar(20) not null, -- 商品名称stock int not null, -- 库存version int not null -- 版本)insert into product (product_name,stock,version) values('锦鲤-清空购物车-大奖',5,0)sql
-- 订单表create table `order`(id varchar(100) primary key, -- 订单编号pid int not null, -- 商品编号userid int not null -- 用户编号)
  • 项目目录结构
添加依赖
简单解释一下build
我们引入的是tomcat7的插件configuration 配置的是端口 和根目录注意哦 记得刷新pom文件 build里面会有爆红 不要紧张 不用管他 后面的配置他会自己消失
xml
<properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><spring.version>5.2.7.RELEASE</spring.version></properties><packaging>war</packaging><dependencies><!-- Spring --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>${spring.version}</version></dependency><!-- MyBatis --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.10</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.7</version></dependency><!-- 连接池 --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.11</version></dependency><!-- 数据库 --><dependency><groupId>MySQL</groupId><artifactId>mysql-connector-JAVA</artifactId><version>8.0.29</version></dependency><!-- junit --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.24</version></dependency></dependencies><build><plugins><!-- maven内嵌的tomcat插件 --><plugin><groupId>org.Apache.tomcat.maven</groupId><!-- 目前apache只提供了tomcat6和tomcat7两个插件 --><artifactId>tomcat7-maven-plugin</artifactId><configuration><port>8002</port><path>/</path></configuration><executions><execution><!-- 打包完成后,运行服务 --><phase>package</phase><goals><goal>run</goal></goals></execution></executions></plugin></plugins></build>折叠 mybatis.xml
注意哦 :仔细查看上面的项目结构 创建相应的文件夹
xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration><!-- 后台的日志输出输出到控制台--><settings><setting name="logImpl" value=https://www.isolves.com/it/cxkf/jiagou/2022-07-20/"STDOUT_LOGGING"/>spring.xml
注意哦 :仔细查看上面的项目结构 创建相应的文件夹
xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 1.扫描包下的注解 --><context:component-scan base-package="controller,service,mApper"/><!-- 2.创建数据连接池对象 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"destroy-method="close"><property name="url" value=https://www.isolves.com/it/cxkf/jiagou/2022-07-20/"jdbc:mysql://localhost:3306/2022_zkproduct?serverTimezone=GMT"/>


推荐阅读