工作中一直都是一个人奋战一人一个项目,使用Maven管理,看这个也挺好,但是总感觉没有充分发挥maven的功能,于是研究了一下这个,网上关于这个的文章很多,虽然不是很好,但我从中收获了很多,在这集百家所长,写一份实战记录,大家跟着我一块做吧
工作中一直都是一个人奋战一人一个项目,使用Maven管理,看这个也挺好,但是总感觉没有充分发挥maven的功能,于是研究了一下这个,网上关于这个的文章很多,虽然不是很好,但我从中收获了很多,在这集百家所长,写一份实战记录,大家跟着我一块做吧!
声明:构建多模块不是最难的,难点是如果把多模块打包成一个执行jar。
SpringBoot官方推崇的是富jar,也就是jar文件启动项目,所以如果在这里打war包我不具体介绍,如果需要的朋友可以给我留言,我回复。
建议clone项目后,在看教程(有不足的地方希望大家保函,指出来,我们一起学习改进)
GitHub:https://github.com/lxchinesszz/multi-boluome.git
构建工程
首先第一步,在github上创建一个公共项目项目名 multi-boluome
把仓库同步到本地,使用Intellij idea打开,把普通项目转换为maven项目【右键:Add Frameworks Support】
删除除了pom文件之外的文件也就是src删除
然后新建File->New->module以此创建(此时会看到pom文件的变化)
==提示:一定要把外面的pom文件中的pom==
引入springBoot依赖 这个我在外面写的(这个根据个人)
外面的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>blm.server</groupId> <artifactId>multi-boluome</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <modules> <module>web</module> <module>service</module> <module>dao</module> <module>domain</module> </modules> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <Kotlin.version>1.0.6</kotlin.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <!--引入mock框架--> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>1.10.19</version> </dependency> <!--RabbitMQ--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aMQp</artifactId> </dependency> <dependency> <groupId>com.Google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.2.4</version> </dependency> </dependencies> <build> <plugins> <plugin> <!-- The plugin rewrites your manifest --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.3.0.RELEASE</version> <configuration><!-- 指定该Main Class为全局的唯一入口 --> <mainClass>iflyer.IflyerApplication</mainClass> <layout>ZIP</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中--> </goals> <!--可以生成不含依赖包的不可执行Jar包--> <!-- configuration> <classifier>exec</classifier> </configuration> --> </execution> </executions> </plugin> </plugins> </build></project>
--结束END--
本文标题: SpringBoot创建maven多模块项目实战代码
本文链接: https://www.lsjlt.com/news/222907.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0