SoFunction
Updated on 2025-05-08

Spring Boot Non-web application implementation

In the Spring Boot framework, you want to create a non-web application (pure Java program)

The main method is run. If tomcat is not started, the main method is executed and the program exits;

Method one

1. When SpringBoot develops pure Java programs, the following starting dependencies should be used:

<!-- SpringbootDevelopmentjavaProject start-up dependency -->
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>

2. Directly in the main method, obtain the returned Spring container object according to the () method, and then obtain the business bean for call;

public static void main(String[] args) {
    ConfigurableApplicationContext context = (, args);
    UserService userService = (UserService)("userService");
    String hello = ("Hello, Spring Boot");
    (hello);
}

Method 2

1. When SpringBoot develops pure Java programs, the following starting dependencies should be used:

<!-- SpringbootDevelopmentjavaProject start-up dependency -->
<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>

2. Spring Boot's entry class implements the CommandLineRunner interface;

3. Override the run() method of the CommandLineRunner interface, and write specific processing logic in the run method.

@Autowired
private UserService userService;
@Override
public void run(String... args) throws Exception {
    String msg = ("zhangshan");
    (msg);
}

This is the end of this article about the implementation of Spring Boot non-web application. For more related Spring Boot non-web application content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!