SpringBoot exception: Process finished with exit code 0 | Tomcat service is not started | cannot be accessed through a browser

error message

After starting the springBoot project, the printed information is as follows

Meaning: The program I should execute has finished executing and exited normally.

Hope to prompt: print Tomcat has started on port 8080 and can be accessed through a browser. If this is the problem, continue to browse down!

wrong reason

When creating a new SpringBoot project, after clicking Next, the options shown in the figure below are not checked.

Therefore, the project is not recognized as a web project, so the Tomcat service is not automatically introduced.

solution

Method 1: Introduce spring-boot-starter-web dependency in pom.xml ( optimal solution )

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

After the introduction, right-click pom.xm and reload it.

Method 2: Click Edit Configurations in the upper right corner to reconfigure the Tomcat service 

 

 Choose the project you want to deploy

 Configure the access path as /

Method 3: Configure the Tomcat container in pom.xml

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

Of course, you can also specify as an underdow or jetty container

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 移除掉默认支持的 Tomcat -->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>


<dependency>
    <groupId>org.springframework.boot</groupId>
    <!-- 添加 Undertow 容器 -->
    <artifactId>spring-boot-starter-undertow</artifactId>
  <!--使用jetty容器-->
  <!--
     <artifactId>spring-boot-starter-jetty</artifactId>
  -->
</dependency>

Show results

 Print information in the background, you can see that Tomcat has started on port 8080

 Normal browser access

 Summarize

I hope to start Tomcat automatically, but the console does not print any Tomcat information, so the first thing that comes to mind is that no web dependencies are introduced in pom.xml,

Think about it with your thighs, oh, just introduce dependencies!

Guess you like

Origin blog.csdn.net/xp871038951/article/details/127610209