框架/工具 关键字
Maven SpringBoot Myatis MySQL Tomcat IDEA
部分操作
新建父工程,New > Project > Maven
,不使用原型(不勾选Create from archetype
) -> 填写项目信息(GroupID:项目组织唯一标识,ArtifactID:项目唯一标识)
删除父工程下src
目录
右键项目,新建子模块(New -> Module),填写项目名称,其他默认即可
|–> 非web模块,不使用原型新建Maven
模块
|–> web模块
|-> 使用maven-archetype-webapp
构建
|-> Spring Initializr
构建Spring
相关项目
新建模块:

简单MVC项目结构如下所示:

- 在各个子模块的pom文件中添加互相的依赖(父工程在前一步自动添加了对应的子模块
<modules>
)

- 添加依赖到父工程的pom中(
Spring Initializr
构建web模块的,把web模块的pom.xml中的依赖改到父工程)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version> <relativePath/> </parent>
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties>
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
|
然后在父工程pom.xml后添加下面内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.5.8.RELEASE</version> <configuration> <mainClass>com.like.DemoWebApplication</mainClass> <layout>ZIP</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals>
</execution> </executions> </plugin> </plugins> </build>
|
web模块pom.xml添加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <build> <finalName>demo-start</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build>
|
右键父项目 > Open Module Settings
进入Project Structure
> 子模块 > Dependencies
> +
> Module Dependency
,添加子模块需要引用的其他子模块
maven打包
配置启动设置,配置为启动web子模块的配置即可

记录
maven统一打包命令(跳过测试)
1
| mvn package —Dmaven.test.skip=true
|
编译/打包报错程序包xxx.xxx.xxx不存在,尝试
子模块间的引用要写在各自的pom文件里的 <dependencies>
中,父工程配置<modules>
即可
引用的jar包写在父工程pom的 <dependencies>
中