[Spring Boot]1.初识Spring Boot

一、Spring Boot是什么

Spring 大量的XML配置以及复杂的依赖管理饱受诟病。Spring Boot是由Pivotal团队提供的全新框架,用来简化Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置。

二、搭建一个Spring Boot项目

方式一、

在这里我使用Maven构建项目,使用的IDE是IntelliJ IDEA

开始建立Maven项目

image

直接Next

image

完成项目的创建

image

添加项目所需的依赖,使用当前最新的Spring Boot 版本 1.4.2.RELEASE
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

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

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
新建一个Application.java
package com.devil;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Created by wangdi on 2016/11/10.
 */
@SpringBootApplication
public class Application {

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

到了这一步最基本的一个Spring Boot 框架就完成了。启动项目验证。
image
说明项目可以正常运行。

新建一个HelloController.java
package com.devil;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wangdi on 2016/11/10.
 */
@RestController
public class HelloController {

    @GetMapping(value = "/hello")
    public String hello(){
        return "Hello World!";
    }
}

国际惯例

测试

image

返回了"Hello World!",直接可以开发Web项目了。节约了大量的搭建一个基础框架的时间。
项目对应的github地址https://github.com/code-wangdi/Spring-Boot-Demo,Project-1目录。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值