SpringBoot入门(一)
什么是springboot
Spring Boot是一个简化Spring开发的框架。用来监护spring应用开发,约定大于配置,去繁就简,just run 就能创建一个独立的,产品级的应用
Spring Boot框架:
1.是一个快速开发框架,在这个框架里我们使用Maven依赖和Maven继承的方式,来实现jar包的整合,来实现整合第三方框架。完全采用注解化的方式、简化了XML配置
优点
- 快速创建独立运行Spring项目以及主流的框架的集成
- 使用嵌入式的servlet容器,无需将我们的项目打包成war包
- starters 自动依赖与版本控制
- 大量的自动配置,简化开发,也可以修改默认值
- 无需配置xml,无代码的生成,开箱即用
- 准生产环境的运行时的应用与监控
- 与云计算的天然集成
与我们的Spring Cloud 构建出我们的微服务框架
一个案例
pom.xml
加入如下两个配置:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
创建一个controller
@Controller
@ComponentScan("com.sxh.controller")
@EnableAutoConfiguration
public class HelloWord {
@RequestMapping(value = "/hello")
@ResponseBody
public String helloword(){
return "helloword!!";
}
public static void main(String[] args) {
SpringApplication.run(HelloWord.class,args);
}
}
运行main
可以看到我们的请求已经被扫描了
访问这个请求
因为有内嵌的tomcat,所以不需要配置tomcat,直接发请求