SpringBoot

What?

关于SpringBoot,搜索了一些资料。可以看看官方给的定义。

SpringBoot:Takes an opinionated view of building production-ready Spring applications. Spring Boot favors convention over configuration and is designed to get you up and running as quickly as possible.

convention over configuration,约定优于配置,也称作按约定编程,是一种软件设计范式,旨在减少软件开发人员需做决定的数量,获得简单的好处,而又不失灵活性。本质是说,开发人员仅需规定引用中不符约定的部分。例如,如果模型中有个名为Sale的类,那么数据库中对应的表就会默认命名为sales。只有在偏离这一约定时,例如将该表命名为“products_sold”,才需写有关这个名字的配置。

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.

Spring Boot使我们更容易去创建基于Spring的独立和产品级的可以”即时运行“的应用和服务。之前我们创建基于Spring的项目需要考虑添加哪些Spring依赖和第三方的依赖。使用Spring Boot后,我们可以以最小化的依赖开始spring应用。大多数Spring Boot应用需要很少的配置即可运行

特性

Features
    Create stand-alone Spring applications
    Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
    Provide opinionated 'starter' POMs to simplify your Maven configuration
    Automatically configure Spring whenever possible
    Provide production-ready features such as metrics, health checks and externalized configuration
    Absolutely no code generation and no requirement for XML configuration

说说Spring Boot的特性
    创建可以独立运行的Spring应用
    直接嵌入 Tomcat 或 Jetty 服务器,不需要部署 WAR 文件。
    提供推荐的基础 POM 文件来简化 Apache Maven 配置。
    尽可能的根据项目依赖来自动配置 Spring 框架。
    提供可以直接在生产环境中使用的功能,如性能指标、应用信息和应用健康检查。
    没有代码生成,也没有 XML 配置文件。

demo

Quick Start,举一个hello world的例子
添加如下配置

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
继承spring-boot-starter-parent后我们可以继承一些默认的依赖,这样就无需添加一堆相应的依赖,把依赖最小化;spring-boot-starter-web提供了对web的支持,还有一个代码中没写的spring-boot-maven-plugin提供了直接运行项目的插件,我们可以直接mvn spring-boot:run运行。

hello/SampleController.java
package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

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

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


从上面代码可以看出,在SampleController中加入@EnableAutoConfiguration开启自动配置,然后通过SpringApplication.run(UserController.class);运行这个控制器;这种方式只运行一个控制器比较方便;在这里给大家另一种运行的方式。


通过@Configuration+@ComponentScan开启注解扫描并自动注册相应的注解Bean。

总结      

引用某大牛的话作为总结:只要Spring框架存在,未来一定是SpringBoot的天地,SpringBoot也一定会被颠覆,会被更加高效的方式取代。

                         

                                                                        微服务以及spring boot快速构建微服务,敬请期待后面的博文。



评论 50
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值