Using development tools: Spring Tool Suite 4
Create a Maven project
-
Select File - > New - > others - > Maven - > Maven project
- Create a simple project(skip archetype selection)
- Use default Workspace location
- Add project(s) to working set
-
Choose project type: usually choose to build Maven archetype QuickStart (non web project) model or Maven archetype webapp (Web project).
-
Fill in project parameters (Group Id, Artifact Id, Version, etc.)
-
The project structure is as follows
-
Modify pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.wljkzx.wcwoa</groupId> <artifactId>ams</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>ams</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <!-- spring-boot-starter-* --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> </dependencies> </project>
Write test code
- Write a simple Controller
package org.wljkzx.wcwoa.ams.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMapping("/hello") public String hello() { return "Hello Spring Boot!"; } }
- Modify Maven's default App class
package org.wljkzx.wcwoa.ams; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * Hello world! * */ @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } }
-
Launch project: use the right-click shortcut menu to run the main method
-
Enter http://localhost:8080/hello access request in browser