阶段一-01.万丈高楼,地基首要-第2章 单体架构设计与准备工作-2-10 聚合工程整合SpringBoot
目前通过maven构建了一个聚合的项目,只不过现在还不能去运行。
要跑起来就需要用到Springboot。我们要把相应的jar包依赖放到我们的pom.xml内

springboot父级的依赖。

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath />
</parent>
jdk的版本号整体设置为1.8

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
默认会使用springboot自带的一个logging。我们这里把这个日志排除掉 。因为我们后续会 整合其他的日志。

spring容器里面包含的一个web模块。

spring默认可以解析到yml。如果项目里面使用了xml也使用了properties。那么其他的一些文件的话,想要被他去解析的话,就需要引入这个依赖。一般来说,这个依赖都会进行引入。

我们引入的这些依赖,全部由父级maven的依赖去进行管理。所以下面引入的就不需要再写上版本号了。

创建yml


图标是一个绿色的叶子,就是代表spring



创建springboot的启动类


controller
这是个web项目那么就需要有控制层



我们要把请求放在控制层去处理的。这里使用@RestController。
@Controller在SpringMvc里面用的比较多,可以去走页面的跳转。使用RestController返回的默认都是json对象。


运行测试
运行之前要注意。我们写了一些代码。聚合工程的pom.xml引入了相应的依赖,在运行之前。必须要进行maven的安装。

双击install

等待安装完毕


可以看到我们的项目已经是启动成功了。

http://localhost:8080/hello

结束
浙公网安备 33010602011771号