第一章:创建项目以及搭建环境配置
1.环境准备
项目搭建环境可以基于SpringBoot/idea/eclipse等主流的java编程软件。在这里就不介绍软件一些配置信息。
2.聚合工程搭建
项目是基于sts来进行开发的,开始创建工程
工程创建出来大致就是这个样子,如上图:
聚合工程:(切换Working Sets)–>个人习惯,可以不换,换只是为了方便看项目的架构和主体。
3.创建聚合工程父级项目
父级工程:
注意:父级工程打包类型必须是pom类型
1.1pom文件添加依赖
<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>com.jt.vip</groupId>
<artifactId>jt</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<!--通过jt父级工程定义统一的jar包的版本 -->
<!--parent当中有一个大型的配置文件,在其中管理了springBoot与第三方整合的 所有(主流的)的jar包的版本 SSM:jar包冲突问题比较严重. -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
<!--maven install时跳过测试类打包 -->
<skipTests>true</skipTests>
</properties>
<dependencies>
<!--当前只是引入jar包文件 暂时没有执行. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<!--spring-boot-starter spring的启动项中自动的完成了项目整合 自动配置 -->
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--添加属性注入依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!--支持热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!--引入插件lombok 自动的set/get/构造方法插件 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--引入数据库驱动 5.5/5.7 5.8数据库则去除版本,使用高版本驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<!--链接数据库代理 使用低版本驱动 -->
<version>5.1.32</version>
</dependency>
<!--springBoot数据库连接 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<!--SpringBoot的启动项 开箱即用 -->
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--spring整合mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
<!--springBoot默认条件下整合的页面html如果需要整合jsp则需要 手动导入jar包 -->
<!--servlet依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<!--jstl依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!--使jsp页面生效 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- 引入aop支持 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--spring整合redis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<!--添加httpClient jar包 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!--引入dubbo配置 -->
<!--<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency> -->
<!--添加Quartz的支持 -->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency> -->
</dependencies>
<!-**-父级项目中不能添加build标签 因为父级项目只是一个标识,不能运行 只有运行的项目才能添加build标签**. -->
</project>
子级工程–>jt-common
选中jt,右键如下:
打包类型:选择jar
注意:父子级关系维护:
<modules>
<module>jt-common</module>
</modules>
–>jt-manage
打包类型选择:war
记得添加添加继承/依赖/插件。
到此聚合工程创建就完成了。
运行测试:
选中main方法,右键–>run as -->spring boot app
这样运行可以防止一些bug的出现。