• [Spring Boot Reference Guide] 读书笔记一 Getting Started


    8. Introducing Spring Boot

    Goals of spring boot:

    • Provide a radically faster and widely accessible getting started experience for all Spring development.
    • Be opinionated out of the box, but get out of the way quickly as requirements start to diverge from the defaults.
    • Provide a range of non-functional features that are common to large classes of projects (e.g. embedded servers, security, metrics, health checks, externalized configuration).
    • Absolutely no code generation and no requirement for XML configuration.

    9. System Requirements

    Spring Boot集成了Tomcat、Jetty等Servlet 3.0+的Web容器。

    10. Installing Spring Boot

    Spring Boot以及Spring Boot CLI的各种安装方法

    11. Developing your first Spring Boot application

    1.

    The spring-boot-starter-parent is a special starter that provides useful Maven defaults. It also provides a dependency-management section so that you can omit version tags for “blessed” dependencies.

    spring-boot-starter-parent提供了所需的依赖,并且可以省略依赖的版本。

    spring-boot-starter-web可以用来生成web程序,自带tomcat等。

    2. 代码:

     1 import org.springframework.boot.*;
     2 import org.springframework.boot.autoconfigure.*;
     3 import org.springframework.stereotype.*;
     4 import org.springframework.web.bind.annotation.*;
     5 
     6 @RestController // REST控制器,直接把字符串渲染后返回给调用者
     7 @EnableAutoConfiguration // 自动配置
     8 public class Example {
     9     @RequestMapping("/") // 路由
    10     String home() {
    11         return "Hello World!";
    12     }
    13     public static void main(String[] args) throws Exception {
    14         SpringApplication.run(Example.class, args);
    15     }
    16 }

    通过以下命令启动

    mvn spring-boot:run
  • 相关阅读:
    Hibernate Tomcat JNDI数据源配置(转)
    使用Spring的@Autowired 实现DAO, Service, Controller三层的注入(转)
    丢弃重口味的xml配置--spring4用groovy配置bean(转)
    Java 对象的生命周期
    设计模式学习总结(23) 中介者模式
    WebSocket初探
    设计模式 之 建造者
    谈谈CListCtrl 扩展风格设置方法-SetExtendedStyle和ModifyStyleEx 比較
    linux signal 处理
    UVA 1546
  • 原文地址:https://www.cnblogs.com/Azurewing/p/4324164.html
Copyright © 2020-2023  润新知