SpringBoot简单多模块框架搭建(1)---先启动再说
新建⼀个maven项⽬(springboot项⽬也可以,⼤家可以试⼀下),然后在项⽬⾥新创建⼏个module,我这⾥创建了三个,⼀个是基础base模块(⼯具类,配置类等都在这⾥)和⼀个hello模块(测试⽤),⼀个final模块(启动项⽬⽤)
⼤概就是创建⼏个模块,⼀个启动模块,⼀个基础类模块,⼏个业务模块,启动模块依赖业务模块,业务模块依赖基础模块
先来个结构图:
第⼀步在根l⾥加⼊⽗级依赖,中央仓库等,代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId&ichao</groupId>
<artifactId>bootframe</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<!-- maven import changes时⾃动⽣成的模块名,不⽤⼿写 -->
<modules>
<module>final</module>
<module>hello</module>
<module>base</module>
</modules>
<!--指定⽗级依赖-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.11.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
&porting.outputEncoding>UTF-8</porting.outputEncoding>
<java.version>1.8</java.version>
<tomcat.version>8.5.56</tomcat.version>
<mavenpiler.source>1.8</mavenpiler.source>
<mavenpiler.target>1.8</mavenpiler.target>
</properties>
<!-- 阿⾥云中央仓库,是真的爽 -->
<repositories>
<repository>
<id>aliyun</id>
<url>maven.aliyun/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<!--只有项⽬本⾝的依赖,⾛了aliyun这个repository,maven命令需要的插件(⽐如clean、install都是maven的插件),⾛的还是默认的repository(repo.ma 所以需要加pluginRepositories-->
<pluginRepositories>
<pluginRepository>
<id>aliyun-plugin</id>
<url>maven.aliyun/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
然后打开base⾥的l,加⼊我们开发需要的jar包依赖等,代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd">
<!-- 这⾥的⽗级依赖是项⽬的根l -->
<parent>
<artifactId>bootframe</artifactId>
<groupId&ichao</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>base</artifactId>
<!-- 下⾯的依赖可根据⾃⼰的需要添加和删除 -->
<dependencies>
<!--添加web依赖,必须-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 添加mybatis依赖,类似⼀个中间件,链接springboot和mybatis,构建基于springboot和mybatis应⽤程序 -->
<dependency>
<groupId&batis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
<!-- 排除tomcat配置的jdbc连接池,我们项⽬⾥Druid连接池 -->
<exclusions>
<exclusion>
<groupId>at</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 数据库mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 阿⾥的数据库连接池druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.29</version>
</dependency>
<!-- aop -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- 内存持久化⽇志redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- JSON解析库 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.73</version>
</dependency>
<!-- android⽹络框架 -->
<!-- android⽹络框架 -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.7.0</version>
</dependency>
springboot aop<!-- 公共基础类,如StringUtils,RandomStringUtils,DateUtils等 -->
<dependency>
<groupId>org.apachemons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- ⽤来读写XML⽂件 -->
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.0.0</version>
</dependency>
<!-- ⽤于摘要运算,编码解码,如Base64,MD5等 -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
</dependency>
<!-- ⽀持http协议的客户端编程⼯具包,基于httpcore -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
<!-- ⼀套http协议的实现包 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.9</version>
</dependency>
<!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<!-- io包 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
</project>
再然后在final模块⾥新建⼀个启动类(新建springboot项⽬的话⾃带启动类)
final模块l代码如下(重要!重要!重要!)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"> <parent>
<artifactId>bootframe</artifactId>
<groupId&ichao</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>final</artifactId>
<!-- 没有这个依赖项⽬启动扫描不到hello⾥的配置哦-->
<!-- 没有这个依赖项⽬启动扫描不到hello⾥的配置哦-->
<!-- 没有这个依赖项⽬启动扫描不到hello⾥的配置哦-->
<!-- 加载依赖hello模块,再有hello模块依赖base -->
<dependencies>
<dependency>
<groupId&ichao</groupId>
<artifactId>hello</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<!-- 当新建其他模块时,记得这⾥加⼊ -->
</project>
下⼀步在hello的l中添加代码如下:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论