【基础篇】parent继承、starter、引导类、内嵌tomcat
warning:
这篇文章距离上次修改已过448天,其中的内容可能已经有所变动。
在Spring Boot中,parent用于继承Spring Boot的默认配置,starter是一系列依赖的集合,用于快速启动Spring Boot项目,引导类是启动Spring Boot应用的入口,而内嵌Tomcat是Spring Boot应用中的一种服务器。
- 使用
parent继承:
在pom.xml中,使用Spring Boot的parent POM可以继承Spring Boot的默认配置。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/>
</parent>- 使用
starter启动:
starter是一系列依赖的集合,用于快速启动特定的应用,比如spring-boot-starter-web用于启动web应用。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>- 引导类:
创建一个带有@SpringBootApplication注解的类,并使用SpringApplication.run()方法启动Spring Boot应用。
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}- 内嵌Tomcat:
在pom.xml中添加spring-boot-starter-tomcat依赖,并使用spring-boot-starter-web依赖中的Tomcat。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>Spring Boot应用默认使用内嵌的Tomcat服务器。如果需要,可以配置application.properties或application.yml文件来更改默认端口或其他服务器设置。
评论已关闭