Table of contents
3. Write the startup main program
I. Introduction
Prerequisites: IDEA, JDK
Create a Maven project
2. Modify pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
</parent>
<!-- web starter, 自动配置SpringMVC,内置tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3. Write the startup main program
package com.iflytek;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.iflytek.dao")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
4. Create Controller
package com.sodaopen.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String sayHello(){
return "Hello, Spring Boot";
}
}
4. Operation
1. Run the main program (rendering):
2. Enter the TomCat URL in the browser:
http://localhost:8080/hello
Final running effect:
Summarize
After deploying the SpringBoot project, you can continue to build more Spring programs.
When the SpringBoot project is deployed together with other projects, the SpringBoot main program may fail to start. The common reason is that other dependencies in the pom file may conflict with SpringBoot dependencies. The solution: Redeploy Spring in a new project. project, or comment out other irrelevant dependencies first.