SpringBoot学习之hello world

来源:互联网 发布:mac蓝光播放软件 编辑:程序博客网 时间:2024/06/05 10:55

Spring Boot是什么?   

一个很好的框架 ,Spring Boot可以轻松创建可以独立运行的 、生产级别的Spring应用程序。以前整合第三方库需要配置很多,现在用Spring Boot应用程序只需要很少的Spring配置。一句话 简化繁琐的配置。

Spring Boot的开发环境

Spring Boot支持java 6以上(可能有问题) ,Spring Boot 1.5.7 需要java7,但是官方建议使用java8( java8还有一堆新特性  赶快安装java8吧 )  

关于Maven  Spring Boot需要Maven3.2以上,如不按上面的环境安装,未知的bug等着你。

Servlet containers方面(官方图片)


入手一个新框架,当然要从它的helloworld开始,步骤如下

1、pom中导入Spring Boot依赖 

     <parent>          <groupId>org.springframework.boot</groupId>          <artifactId>spring-boot-starter-parent</artifactId>          <version>1.5.7.RELEASE</version>     </parent>     <dependencies>          <dependency>              <groupId>org.springframework.boot</groupId>               <artifactId>spring-boot-starter-web</artifactId>          </dependency>     </dependencies>


2、写代码 
package hello;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/*** @author shan* @time 创建时间:2017年9月14日 下午2:12:18**/@RestController@EnableAutoConfigurationpublic class SampleController {    @RequestMapping("/")    String home() {        return "Hello World!";    }    public static void main(String[] args) throws Exception {        SpringApplication.run(SampleController.class, args);    }}



3、在浏览器中输入网址    即可看到下面的结果,hello world成功!