SpringBoot入门案例
1.1:pom.xml
< ? xml version= "1.0" encoding= "UTF-8" ? >
< 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>
< parent>
< groupId> org. springframework. boot< / groupId>
< artifactId> spring- boot- starter- parent< / artifactId>
< version> 2.5 .4 < / version>
< / parent>
< groupId> com. project< / groupId>
< artifactId> springboot__quickstart< / artifactId>
< version> 1.0 - SNAPSHOT< / version>
< properties>
< maven. compiler. source> 8 < / maven. compiler. source>
< maven. compiler. target> 8 < / maven. compiler. target>
< / properties>
< dependencies>
< dependency>
< groupId> org. springframework. boot< / groupId>
< artifactId> spring- boot- starter- web< / artifactId>
< / dependency>
< / dependencies>
< / project>
1.2:启动类
@SpringBootApplication
public class Application {
public static void main ( String [ ] args) {
SpringApplication . run ( Application . class ) ;
}
}
1.3:controller类
@RestController
@RequestMapping ( "/books" )
public class BookController {
@GetMapping
public String getById ( ) {
System . out. println ( "springboot is running...4" ) ;
return "springboot is running...4" ;
}
}
1.4:更换内嵌tomcat
< dependencies>
< dependency>
< groupId> org.springframework.boot< /groupId>
< artifactId> spring-boot-starter-web< /artifactId>
< ! --web起步依赖环境中,排除Tomcat起步依赖-->
< exclusions>
< exclusion>
< groupId> org.springframework.boot< /groupId>
< artifactId> spring-boot-starter-tomcat< /artifactId>
< /exclusion>
< /exclusions>
< /dependency>
< ! --添加Jetty起步依赖,版本由SpringBoot的starter控制-->
< dependency>
< groupId> org.springframework.boot< /groupId>
< artifactId> spring-boot-starter-jetty< /artifactId>
< /dependency>
< /dependencies>