1。打开的想法,创建新项目,选择春天Initializr
5。进入项目,可以将以下内容删除
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt;项目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”比; & lt; modelVersion> 4.0.0 & lt; groupId> com.example & lt; artifactId> springbootdemo & lt; version> 0.0.1-SNAPSHOT & lt; packaging> jar & lt; name> springbootdemo 春天Boot< & lt; description>演示项目;/description> & lt; !——起步依赖——比; & lt; parent> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-parent & lt; version> 1.5.2.RELEASE & lt; relativePath/比;& lt; !——从库中查找父——比; & lt;/parent> & lt; properties> & lt; project.build.sourceEncoding> UTF-8 & lt; project.reporting.outputEncoding> UTF-8 & lt; java.version> 1.8 & lt;/java.version> & lt;/properties> & lt; dependencies> & lt; !——开发网络项目相关依赖——比; & lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-web & lt;/dependency> & lt; !——springboot单元测试——比; & lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-test & lt; scope> test & lt;/dependency> & lt;/dependencies> & lt; !——maven构建——比; & lt; build> & lt; plugins> & lt; plugin> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-maven-plugin & lt;/plugin> & lt;/plugins> & lt;/build> & lt;/project>>之前
6。创建一个HelloController
com . example,包 进口org.springframework.web.bind.annotation.RequestMapping; 进口org.springframework.web.bind.annotation.RestController; @RestController 公开课HelloController { @RequestMapping(“/hello”) 公共字符串hello () { 返回“你好,我是一个springboot演示”; } }
7。程序自动生成的SpringbootdemoApplication,会有一个@SpringBootApplication的注解,这个注解用来标明这个类是程序的入口
com . example,包 进口org.springframework.boot.SpringApplication; 进口org.springframework.boot.autoconfigure.SpringBootApplication;//入口 @SpringBootApplication 公开课SpringbootdemoApplication { 公共静态void main (String [] args) { SpringApplication.run (SpringbootdemoApplication.class, args); } }
@SpringBootApplication开启了春天的组件扫描和springboot的自动配置功能,相当于将以下三个注解组合在了一起
(1) @ configuration:表名该类使用基于Java的配置,将此类作为配置类
(2) @ComponentScan:启用注解扫描
(3) @EnableAutoConfiguration:开启springboot的自动配置功能
8。运行SpringbootdemoApplication类