Spring Boot最快入门
它使用“习惯优于配置”(项目中存在大量的配置,此外还内置了一个习惯性的配置,让你无需手动 配置)的理念让你的项目快速运行起来。
-
Spring Boot整合了所有框架
-
简化Spring应用开发的一个框架
Features
-
创建独立的Spring应用程序
-
直接嵌入Tomcat,Jetty或Undertow(无需部署WAR文件)
-
提供“初始”的POM文件内容,以简化Maven配置
-
尽可能自动配置Spring
-
提供生产就绪的功能,如指标,健康检查和外部化配置
-
绝对无代码生成,也不需要XML配置
版本区别
-
GA: General Availability,正式发布的版本,官方推荐使用此版本。在国外都是用GA来说明release版本的。
-
PRE: 预览版,内部测试版。主要是给开发人员和测试人员测试和找BUG用的,不建议使用。
-
SNAPSHOT : 快照版,可以稳定使用,且仍在继续改进版本。
环境搭建
-
使用IDE搭建(推荐使用IDEA),File>New > Project>Spring Initializr
-
maven搭建,项目创建好后,导入Spring Boot的相关依赖
<!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.5.RELEASE</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <!-- Package as an executable jar --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
应用入口类
@SpringBootApplication
//@SpringBootApplication是Sprnig Boot项目的核心注解,主要目的是开启自动配置
/*@SpringBootApplicatio相当于
@Configuration(proxyBeanMethods = false)
@EnableAutoConfiguration
@Import({ MyConfig.class, MyAnotherConfig.class })
*/
public class SpringbootReApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootReApplication.class, args);
}
}
Conteoller类
@Controller
public class HelloWorldController {
@ResponseBody
@RequestMapping("/hello")
public String index() {
return "hello, yhx!";
}
}
更多可以查看个人博客:http://xiaobear.cn/