1、环境准备
操作系统:win10
开发工具:IntelliJ IDEA
数据库:MySQL
底层工具:dubbo admin(没有也完全可以) + zookeeper
框架:springMVC+mybatis
工程:maven
2、工程搭建后的结构图
开始搭建前,先看一下搭建好后的结构
其中:tea-api模块:接口和实体类的信息,也是暴露给服务调用者的模块
tea-service模块下的2个子模块:basic-service和biz-server,是服务提供者,basic是提供数据库层的服务,biz提供其他的,比如redis 的调用等,示例中,只是写了一段输出
tea-web模块下的crm-web模块,是服务调用者,对外展示的通道(crm嘛,当然就能想到后台管理系统了)
3、搭建前的准备
3.1、安装zookeeper
3.1.1、下载zookeeper
直接官网下载:https://www.apache.org/dyn/closer.cgi/zookeeper/
3.1.2:修改zk 的配置文件
下载并且解压后,进入zk 的conf目录,将zoo_sample.cfg文件复制并命名为zoo.cfg,修改其中的配置:
如图中标红的,一个是zk 的节点存放目录,clientPort是zk 的端口
3.1.3:启动zk服务
改完后,保存,进入bin目录,执行zkServer.cmd文件,启动zk服务
3.2:其他的准备
安装maven和idea,这些部分就不一一介绍了,度娘一下就好
4、搭建环境
4.1、新建project
idea和eclipse 的不同点其中一个就是project+module,idea下新建project需要新打开窗口(一个窗口=一个项目),但是project下面可以new module
因为是一个总的父类工程,所以这个下面,核心的就是一个pom文件,如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.chuanyi</groupId>
<artifactId>tea</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>tea</name>
<modules>
<module>tea-api</module>
<module>tea-service</module>
<module>tea-web</module>
</modules>
<!--使用到的第三方jar版本-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- spring版本号 -->
<spring.version>4.0.2.RELEASE</spring.version>
<!-- log4j日志文件管理包版本 -->
<slf4j.version>1.7.7</slf4j.version>
<log4j.version>1.2.17</log4j.version>
<commons-lang3.version>3.3.2</commons-lang3.version>
<zookeeper.version>3.4.12</zookeeper.version>
<zkclient.version>0.10</zkclient.version>
<junit.version>3.8.1</junit.version>
<mybatis.version>3.2.2</mybatis.version>
<javaee.api.version>5</javaee.api.version>
<mybatis.spring.version>1.3.0</mybatis.spring.version>
<javassist.version>3.17.1-GA</javassist.version>
<cglib.version>2.2.2</cglib.version>
<c3p0.version>0.9.1.2</c3p0.version>
<ojdbc.version>12.1.0.1-atlassian-hosted</ojdbc.version>
<mysql.connector.java.version>5.1.30</mysql.connector.java.version>
<commons.dbcp.version>1.2.2</commons.dbcp.version>
<jstl.version>1.2</jstl.version>
<fastjson.version>1.1.41</fastjson.version>
<jackson.mapper.asl.version>1.9.13</jackson.mapper.asl.version>
<commons.fileupload.version>1.3.1</commons.fileupload.version>
<commons.io.version>2.4</commons.io.version>
<commons.codec.version>1.9</commons.codec.version>
<jedis.version>2.9.0</jedis.version>
<spring.data.redis.version>1.6.6.RELEASE</spring.data.redis.version>
<mybatis.ehcache.version>1.0.0</mybatis.ehcache.version>
<druid.version>1.0.18</druid.version>
<junit.jupiter.api.version>RELEASE</junit.jupiter.api.version>
<quartz.version>2.2.3</quartz.version>
<dubbo.version>2.5.7</dubbo.version>
<jackson-core.version>2.8.8</jackson-core.version>
<netty.version>3.9.5.Final</netty.version>
<netty-all.version>4.1.16.Final</netty-all.version>
<commons.httpclient.version>3.1</commons.httpclient.version>
</properties>
<distributionManagement>
<site>
<id>site</id>
<name>project website</name>
<url>scp://local.company.com/websites/project.company.com/</url>
</site>
</distributionManagement>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>cn.chuanyi</groupId>
<artifactId>logging</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.chuanyi</groupId>
<artifactId>primary-source</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.chuanyi</groupId>
<artifactId>servlet</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>cn.chuanyi</groupId>
<artifactId>ejbs</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javaee</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee.api.version}</version>
</dependency>
<!-- spring核心包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</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-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</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-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis.spring.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>${cglib.version}</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle/ojdbc6 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${ojdbc.version}</version>
<scope>test</scope>
</dependency>
<!-- 导入Mysql数据库链接jar包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.java.version}</version>
</dependency>
<!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>${commons.dbcp.version}</version>
</dependency>
<!-- JSTL标签类 -->
<dependency>
<groupId>jstl</groupId>
&