Springboot启动tomcat怎么启动的
时间: 2024-05-10 14:20:16 浏览: 16
Spring Boot会自动在classpath中查找可用的servlet容器,如果存在就会自动启动。默认情况下,Spring Boot使用embedded Tomcat作为servlet容器。可以通过以下步骤启动embedded Tomcat:
1. 在pom.xml中添加以下依赖:
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
```
2. 编写一个启动类,该类必须包含`@SpringBootApplication`注解,并且有一个`main`方法用于启动应用程序。例如:
```
@SpringBootApplication
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
```
3. 运行该类的`main`方法,启动应用程序。
4. 打开浏览器,访问`http://localhost:8080`,应该能看到Spring Boot的欢迎页面。
如果想使用其他servlet容器,可以在pom.xml中添加相应的依赖,如下所示:
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
```
然后在启动类中添加以下代码:
```
@SpringBootApplication
public class MyApp {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(MyApp.class);
app.setDefaultProperties(Collections.singletonMap("server.port", "8080"));
app.run(args);
}
}
```
这样就使用Jetty作为servlet容器启动了应用程序。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)