[Untitled] SpringBoot in idea does not respond when clicked to run, the button is gray

Problem Description

When using Spring Boot to develop a project, you may encounter a problem: after clicking the run button, there is no output on the console and the project interface is not displayed. This situation can be caused by a variety of reasons, and this article will introduce some common solutions.

Solution

First check whether the Groovy plug-in is selected and deselect it.
Insert image description here
Insert image description here

1. Check whether the port is occupied

First, we need to check whether the port used by the application is occupied by other programs. You can try the following methods:

  • Enter in the command line netstat -ano | findstr "端口号"to check whether the port is occupied. If it is occupied, you can change the port number of the application or close the program occupying the port.
  • If you are using an IDE, you can modify the port number in the running configuration, or check in the Task Manager to see if other programs occupy the port.

2. Check whether the startup class is correct

Make sure the annotation is added to the startup class of the project @SpringBootApplicationand the package path of the startup class is correct. For example:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(Application.class, args);
    }
}

3. Check the log output

Review the project's log output to determine if there are any unusual messages. The log level and output path can be configured in the application.propertiesor file. application.ymlFor example:

# application.properties
logging.level.root=info
logging.file.name=myapp.log

or

# application.yml
logging:
  level: root
  file: myapp.log

Then, check the log file in the project root directory and analyze whether there is any abnormal information. If there is abnormal information, perform corresponding processing according to the abnormal information.

4. Check whether the dependencies are added correctly

Make sure the dependencies in the project have been correctly added to the pom.xml(Maven) or build.gradle(Gradle) file. You can try to re-download the dependencies and update the project. For example, for a Maven project, you can execute the following command on the command line:

mvn clean install -U

For Gradle projects, you can execute the following commands on the command line:

gradle clean build --refresh-dependencies -DincludeScope=compile -U

5. Check whether the startup parameters are set correctly

Make sure the project's startup parameters are set correctly. For example, for a Spring Boot web project, startup parameters can be configured in the application.propertiesor application.ymlfile. For example:

# application.properties
server.port=8080

or

# application.yml
server:
  port: 8080

Then, modify the startup parameters in the running configuration, or use annotations in the code @Valueto obtain the startup parameter values. For example:

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyController {
    
    
    @Value("${server.port}")
    private String port;

    @GetMapping("/port")
    public String getPort() {
    
    
        return port;
    }
}
```@[TOC](这里写自定义目录标题)

Guess you like

Origin blog.csdn.net/luansj/article/details/132459713