springboot介绍

springboot官网:Spring | HomeLevel up your Java code and explore what Spring can do for you.icon-default.png?t=N7T8https://spring.io/

开发手册:

开发手册:Spring Boot Reference Documentationicon-default.png?t=N7T8https://docs.spring.io/spring-boot/docs/2.7.18/reference/htmlsingle/#getting-started.first-application

springboot特点:

新建springboot项目,加入parent:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

加入依赖:

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

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

写主启动类:

@RestController    // 即 @Controller 和 @ResponseBody
@SpringBootApplication
public class MyApplication {

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

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

}

安装ApiPost插件,在IDE中测试(替代postman)

(首先启动服务)

也通过 https://start.spring.io/ 帮助搭建项目脚手架:

springboot特性1:属性管理

spring-boot-starter-parent的父pom是spring-boot-dependencies

在spring-boot-dependencies.pom里面包含了开发中常用的版本集合。

如果我们只是使用默认的版本,那么引入dependency即可;但是如果我们需要自定义依 赖版本,那么额外还需要在标签中引入自定义的版本。

特性2:场景starter

我们引入什么场景的starter,那么就会将一整套场景的jar包都引入进来,我们也不需要关 注多jar包直接的版本号是否兼容彼此,这块工作spring已经帮我们做好了。

SpringBoot提供的Starter有哪些:Build Systems :: Spring Booticon-default.png?t=N7T8https://docs.spring.io/spring-boot/reference/using/build-systems.html#using.build-systems.starters分为三类Starter,分别为:

application starters

production starters

technical starters

核心starter:

特性3:自动配置AutoConfiguration

SpringBoot所有的自动配置功能都在spring-boot-autoconfigure包里面。

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

特性4:默认包扫描路径

主程序MyApplication.java所在的包及其下面的所有子包里面的组件都会被默认扫描。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值