SpringBoot创建多模块项⽬和所遇到的问题
⼀:创建SpringBoot多模块项⽬(这⾥采⽤idea⼯具进⾏创建)
0.先说下这个项⽬的组织:这个项⽬有个以下⼏个模块,分别是common[公共],entity[实体类],dao[数据访问],service[业务], controller[api接⼝1],sys[api接⼝2]
common是独⽴的模块,不依赖谁
entity依赖common
dao依赖entity,common
service依赖dao,entity,common
controller 和sys 依赖 service,dao,entity,common
1.创建⼀个⽗项⽬,先不⽤加依赖,和平时创建SpringBoot项⽬⼀样
这⾥是⽗ pom⽂件 需要注意的是⽗项⽬不需要打包,需要删除<bulid>⾥⾯的默认打包 plugin,如下所⽰
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId&ule</groupId>
<artifactId>askdao</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>askdao</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<mapper.starter.version>2.0.2</mapper.starter.version>
<pageHelper.starter.version>1.2.3</pageHelper.starter.version>
<mybatis.starter.version>2.0.0</mybatis.starter.version>
</properties>
<!--这⾥是⼦模块-->
<modules>
<module>askdao-entity</module>
<module>askdao-dao</module>
<module>askdao-dao</module>
<module>askdao-service</module>
<module>askdao-controller</module>
<module>askdao-common</module>
<module>askdao-sys</module>
</modules>
<!--先不加依赖-->
<dependencies>
</dependencies>
<!--注意:⽗类不需要打包,所以得删除默认的spring-boot-maven-plugin-->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
2.然后在已经创建好的⽗项⽬下创建模块,⽐如common,entity,dao,service,[controller,sys ]等
new-->Module,然后就和上⾯创建⽗项⽬的过程⼀致,也不⽤加依赖,其中根据业务需求,common,entity,dao,servce 这⼏个模块不需要打包,所以可以去掉 build,也可以删除相应的启动类,贴出这⼏个模块的pom⽂件
<?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>
<parent>
<groupId&ule</groupId>
<artifactId>askdao</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../l</relativePath>
</parent>
<groupId&ule</groupId>
<artifactId>askdao-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>askdao-common</name>
<description>Demo project for Spring Boot</description>
<dependencies>
</dependencies>
</project>
<?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>
<parent>
<groupId&ule</groupId>
<artifactId>askdao</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../l</relativePath>
</parent>
<groupId&ule</groupId>
<artifactId>askdao-entity</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>askdao-entity</name>
<description>Demo project for Spring Boot</description>
<dependencies>
<dependency>
<groupId&ule</groupId>
<artifactId>askdao-common</artifactId>
springboot结构
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。