SpringBoot Day1 快速了解

来源:互联网 发布:世界杯小组抽签软件 编辑:程序博客网 时间:2024/06/05 17:15

spring boot是什么?

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。

spring boot的特性

1. 创建独立的Spring应用程序2. 嵌入的Tomcat,无需部署WAR文件3. 简化Maven配置4. 自动配置Spring5. 提供生产就绪型功能,如指标,健康检查和外部配置6. 绝对没有代码生成和对XML没有要求配置

快速入手

  • gradle配置
group 'com.tcwloy'version '1.0-SNAPSHOT'buildscript{    repositories{        mavenCentral()    }    dependencies{        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")    }}apply plugin: 'java'apply plugin: 'org.springframework.boot'jar{    baseName = "springboot-day1"    version = '0.1.0'}sourceCompatibility = 1.8targetCompatibility = 1.8repositories {    mavenCentral()}dependencies {    testCompile group: 'junit', name: 'junit', version: '4.12'    testCompile("org.springframework.boot:spring-boot-starter-test")    compile("org.springframework.boot:spring-boot-starter-web")}
  • 程序入口
package com.tcwloy.day1;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class Application {    public static void main(String[] args) {        SpringApplication.run(Application.class, args);    }}
  • 发布接口
package com.tcwloy.day1.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloWorldController {    @RequestMapping("/hello")    public String index(){        return "hello world!";    }}
  • 查看效果

通过http://localhost:8080/hello查看,页面简单的显示hello world!

0 0