美文网首页
如何学习Spring Boot

如何学习Spring Boot

作者: 青柠_efca | 来源:发表于2019-03-18 20:27 被阅读0次

springboo定义

Spring Boot可以轻松创建单独的,基于生产级的Spring应用程序,您需要做的可能“仅仅是去运行”。 我们提供了Spring Platform对Spring 框架和第三方库进行处理,尽可能的降低使用的复杂度。大多数情况下Spring Boot应用只需要非常少的配置。

Spring boot的特点

  • 快速构建独立的Spring Application,使用内嵌容器,无需部署到外部容器,你要做的仅仅是运行她。
  • 提供众多扩展的‘starter’,通过依赖探知自动配置,你要做的仅仅是添加Maven依赖。
  • 提供生产环境下的性能健康状态监控及外部化配置,让你时刻掌控她。
  • 无需生成代码及XML配置,一切从简。

配置你项目的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.springboot</groupId>
    <artifactId>quickstart</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>quickstart</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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-devtools</artifactId>
            <optional>true</optional>
            <scope>true</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- 如果没有该项配置devtools不会起作用-->
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

创建Application.java

package com.springboot.quickstrat.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * SpringBoot的第一个RESful的请求
 *
 */
@RestController
public class HelloController {

    @RequestMapping(value="/hello" ,method= RequestMethod.GET)
    public String getHello(){
        return "Hello,Spring Boot~~";
    }
}

启动主类

package com.springboot.quickstrat;
/**
 * SpringBoot的启动主类
 */

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

@SpringBootApplication
public class QuickstratApplication {

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

}

运行结果:

image

相关文章

网友评论

      本文标题:如何学习Spring Boot

      本文链接:https://www.haomeiwen.com/subject/xjfimqtx.html