Spring Boot 2.6.13 application immediately shuts down using command line to start

  Kiến thức lập trình

Tools:

  • Windows 11
  • Sprint Boot 2.6.13
  • Command line
  • openjdk version “1.8.0_362”
  • OpenJDK Runtime Environment (Temurin)(build 1.8.0_362-b09)
  • OpenJDK Client VM (Temurin)(build 25.362-b09, mixed mode)

Project structure
Project structure img

“hello” folder to store the class file
hello_img

“config” folder to store the properties
config_img

DemoApplication.java is

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

@SpringBootApplication
public class DemoApplication {

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

}

HelloController.java is

package hello;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {
    @ResponseBody
    @RequestMapping("/")
    public String sayHello(){
        return "Hello, world! ";
    }
}

application.properties is

# web port
server.port=8080

Compile instruction is

javac -d . -classpath spring-boot-2.6.13.jar;spring-boot-autoconfigure-2.6.13.jar;spring-boot-devtools-2.6.13.jar;spring-boot-starter-2.6.13.jar;spring-boot-starter-web-2.6.13.jar;spring-context-5.3.23.jar;spring-core-5.3.23.jar;spring-expression-5.3.23.jar;spring-web-5.3.23.jar;spring-beans-5.3.23.jar;commons-logging-1.1.1.jar;spring-webmvc-5.3.23.jar;spring-aop-5.3.23.jar; DemoApplication.java HelloController.java

run instruction is

java -classpath .;spring-boot-2.6.13.jar;spring-boot-autoconfigure-2.6.13.jar;spring-boot-devtools-2.6.13.jar;spring-boot-starter-2.6.13.jar;spring-boot-starter-web-2.6.13.jar;spring-context-5.3.23.jar;spring-core-5.3.23.jar;spring-expression-5.3.23.jar;spring-web-5.3.23.jar;spring-beans-5.3.23.jar;commons-logging-1.1.1.jar;spring-webmvc-5.3.23.jar;spring-aop-5.3.23.jar; hello.DemoApplication --spring.config.location=D:\ideaProject\Test\Test\Test_SpringBoot\config\application.properties

run result is

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _    
( ( )___ | '_ | '_| | '_ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |___, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::               (v2.6.13)

[2024-01-15 14:55:18.255] - 81044 Inf [restartedMain] --- hello.DemoApplication: Starting DemoApplication using Java 1.8.0_362 on LAPTOP-3CQLL008 with PID 81044 (D:ideaProjectTestTestTest_SpringBoot started by lenovo in D:ideaProjectTestTestTest_SpringBoot)
[2024-01-15 14:55:18.278] - 81044 Inf [restartedMain] --- hello.DemoApplication: No active profile set, falling back to 1 default profile: "default"
[2024-01-15 14:55:18.374] - 81044 Inf [restartedMain] --- org.springframework.boot.devtools.env.DevToolsPropertyDefaultsPostProcessor: Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
[2024-01-15 14:55:19.387] - 81044 Inf [restartedMain] --- org.springframework.boot.devtools.autoconfigure.OptionalLiveReloadServer: LiveReload server is running on port 35729
[2024-01-15 14:55:19.424] - 81044 Inf [restartedMain] --- hello.DemoApplication: Started DemoApplication in 1.832 seconds (JVM running for 2.359)

However, I can’t use url “http://localhost:8080/” to open page

I have use wmic process get name,executablepath,processid|findstr 81044 to find spring-boot process by PID 81044, but it doesn’t exit.

New contributor

jack win is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT