Spring Boot学习之路一:入门

spring boot介绍

所谓的介绍也就是spring boot是什么东西?干什么用的?用了之后对我有什么好处?为什么要用这个而不用其他的?
spring boot是什么东西?

Spring Boot是由Pivotal团队提供的全新框架。

干什么用的?

其设计目的是用来简化新Spring应用的初始搭建以及开发过程。

用了之后对我有什么好处?

简化项目搭建

为什么要用这个而不用其他的?

简化配置
开箱即用
没有代码生成
不需要XML配置。
提供一系列大型项目常用的非功能性特征

要求

这个系列的就用1.5.7版本。这里我使用的是JDK1.8,也可以使用1.7,1.6我就不知道了(没试过),不过建议使用1.8。
这里写图片描述

然后项目管理工具就用Maven,Gradle也可以使用(好像更方便)。

开发第一个Spring Boot应用

项目结构图

项目结构图
父项目的pom配置

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

子项目的pom配置

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

启动类

@Controller
@EnableAutoConfiguration
public class App {

    @ResponseBody
    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(App.class, args);
    }
}

是右键RUN启动哦。不是放到tomcat中,然后启动tomcat哦。
启动时控制台输出如下
这里写图片描述

启动成功后浏览器访问,如下

这里写图片描述

到这里,第一个springboot项目就完成了

代码见Github地址

猜你喜欢

转载自blog.csdn.net/u013239111/article/details/78012640