企业自有网站,外贸短视频营销,河南省城乡建设厅官网,重庆最新消息今天最近在写一个多模块的SpringBoot项目#xff0c;基于过程总了一些总结#xff0c;故把SpringBoot多个模块的项目创建记录下来。
首先#xff0c;先建立一个父工程#xff1a; #xff08;1#xff09;在IDEA工具栏选择File-New-Project #xff08;2#xff0…最近在写一个多模块的SpringBoot项目基于过程总了一些总结故把SpringBoot多个模块的项目创建记录下来。
首先先建立一个父工程 1在IDEA工具栏选择File-New-Project 2选择Spring Initializr,默认选择Default然后点击Next: 3在输入框填写以下截图内容点击Next 4直接点Next无需选择 5直接点击Finish完成创建 6按照以上步骤可以生成以下的项目目录结构 7这时把没用的.mvn目录src目录mvnw还有mvnw.cmd都删除最终只保留.gitignore和pom.xml若是web项目可在该pom.xml里添加以下依赖 1 !--web特征--
2 dependency
3 groupIdorg.springframework.boot/groupId
4 artifactIdspring-boot-starter-web/artifactId
5 version2.3.1.RELEASE/version
6 /dependency 最终得到以下的父结构目录 以上是创建父模块下面创建子模块 1在父模块的根目录fte上点右键在弹出的框里选择New-Module 2选择Maven点击Next 3填写以下内容点击Next 4填写Module,点击Finish 5同理添加fte-controller,fte-dao,fte-service,fte-web,最终得到以下的目录结构 6增加模块之间的依赖 controller层添加以下依赖 1 dependencies2 dependency3 groupIdcom.example/groupId4 artifactIdfte-common/artifactId5 version0.0.1-SNAPSHOT/version6 /dependency7 8 dependency9 groupIdcom.example/groupId
10 artifactIdfte-dao/artifactId
11 version0.0.1-SNAPSHOT/version
12 /dependency
13
14 dependency
15 groupIdcom.example/groupId
16 artifactIdfte-service/artifactId
17 version0.0.1-SNAPSHOT/version
18 /dependency
19 /dependencies service层添加以下依赖 1 dependencies
2 dependency
3 groupIdcom.example/groupId
4 artifactIdfte-dao/artifactId
5 version0.0.1-SNAPSHOT/version
6 /dependency
7 /dependencies 7测试 在fte-controller创建com.zhu.fte.web包增加以下两个类
fteWebApplication类 1 package com.zhu.fte.web;2 3 import org.springframework.boot.SpringApplication;4 import org.springframework.boot.autoconfigure.SpringBootApplication;5 6 SpringBootApplication7 public class fteWebApplication {8 public static void main(String[] args) {9 SpringApplication.run(fteWebApplication.class,args);
10 }
11 }DemoController类 1 package java.com.zhu.fte.web;2 3 import org.springframework.web.bind.annotation.GetMapping;4 import org.springframework.web.bind.annotation.RequestMapping;5 import org.springframework.web.bind.annotation.RestController;6 7 RestController8 RequestMapping(demo)9 public class DemoController {
10
11 GetMapping(test)
12 public String test(){
13 return hello world;
14 }
15
16 } 运行发现出现错误
出现错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project fte-common: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test failed: Plugin org.apache.maven.plugins:maven-surefire-plugin:2.22.2 or one of its dependencies could not be resolved: Could not transfer artifact junit:junit:jar:4.12 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.52.215] failed: Connection timed out: connect - [Help 1]
把缺少的org.apache.maven.plugins手动放到父工程的pom.xml里 1 build2 plugins3 plugin4 groupIdorg.apache.maven.plugins/groupId5 artifactIdmaven-clean-plugin/artifactId6 version2.5/version7 /plugin8 plugin9 groupIdorg.apache.maven.plugins/groupId
10 artifactIdmaven-source-plugin/artifactId
11 version2.2/version
12 /plugin
13 plugin
14 groupIdorg.apache.maven.plugins/groupId
15 artifactIdmaven-compiler-plugin/artifactId
16 version3.0/version
17 configuration
18 source1.8/source
19 target1.8/target
20 encoding${file.encoding}/encoding
21 !--编译的时候方法不改变方法参数名称用于支持使用反射获取方法参数名称--
22 compilerArgument-parameters/compilerArgument
23 /configuration
24 /plugin
25 plugin
26 groupIdorg.apache.maven.plugins/groupId
27 artifactIdmaven-install-plugin/artifactId
28 version2.4/version
29 /plugin
30 plugin
31 groupIdorg.apache.maven.plugins/groupId
32 artifactIdmaven-jar-plugin/artifactId
33 version2.4/version
34 configuration
35 archive
36 manifest
37 addDefaultImplementationEntriestrue
38 /addDefaultImplementationEntries
39 /manifest
40 /archive
41 /configuration
42 /plugin
43
44 plugin
45 groupIdorg.apache.maven.plugins/groupId
46 artifactIdmaven-surefire-plugin/artifactId
47 version2.13/version
48 configuration
49 argLine-Xmx512M -Dfile.encoding${file.encoding}/argLine
50 /configuration
51 /plugin
52 /plugins
53 /build 运行fteWebApplication类里的main方法默认端口为8080访问http://localhost:8080/demo/test正常出现以下情况 按照以上步骤就可以初步建立SpringBoot多模块的项目下一章将基于这个基础搭建Mybatis以及其逆向工程。