继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Spring Boot —— spring-boot-starter-parent

慕的地10843
关注TA
已关注
手记 1081
粉丝 201
获赞 962

你的项目pom.xml文件中,应该存在如下代码:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version></parent>

你是否知道这是干啥的?

这是Spring Boot的父级依赖,这样当前的项目就是Spring Boot项目了。
spring-boot-starter-parent 是一个特殊的starter,它用来提供相关的Maven默认依赖。使用它之后,常用的包依赖可以省去version标签。

当我们搭建web应用的时候,可以像下面这样添加spring-boot-starter-web依赖:

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

简单的演示下 Spring Boot 项目:

maven文件看起来是这个样子的:

<?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>

    <groupId>springBootLearn</groupId>
    <artifactId>springBootLearn</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
    </parent>

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

HelloworldController.java

@RestControllerpublic class HelloworldController {    @RequestMapping("/")    public String say(){        return "Hello Spring Boot";
    }
}

Application.java

@SpringBootApplicationpublic class Application {    public static void main(String[] args) {
        SpringApplication.run(Ch1Application.class, args);
    }
}

运行main方法,启动项目,然后在浏览器访问http://localhost:8080,就能看到 "Hello Spring Boot"。



作者:打铁大师
链接:https://www.jianshu.com/p/54cdfe4e0cac


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP