• SpringBoot-快速搭建并快速验证是否可用


    maven导包创建SpringBoot

    这种最常见,一般项目是很多框架搭配使用的一般就导入 SpringBoot maven地址
    我写文章时最新稳定版本是:2.7.2版本
    在 pom.xml 文件中导入:

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.7.2</version>
        </parent>
        
    	<dependencies>
    	    <dependency>
    	        <groupId>org.springframework.boot</groupId>
    	        <artifactId>spring-boot-starter-web</artifactId>
    	    </dependency>
    	</dependencies>
    	
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    在包下面写一个SpringBoot启动类:

    比如我的叫 MyApplication代码如下:

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class MyApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(MyApplication.class, args);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    在 resources 包下 建立一个 application.yml文件:

    这个是为了以后的配置做准备,比如我更改 Tomcat 端口:

    server:
      port: 8081
    
    
    • 1
    • 2
    • 3

    建立 controller层验证SpringBoot启动是否正常

    建立 controller 包 在包下面建立一个 UserController.java 代码如下:

    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class UserController {
    
        @GetMapping("/cc")
        public String text1(){
            return "成功访问";
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    运行启动类,浏览器访问查看是否成功:
    在这里插入图片描述

    这样就快速搭建了一个 SpringBoot项目并启动验证是否可以正常使用了

  • 相关阅读:
    R语言爬虫程序自动爬取图片并下载
    mysql使用--简单查询
    批量导入Npm包依赖到Nexus私服(批量上传脚本)
    MySQL报错:json_contains: “The document is empty.“ at position 0.
    Linux:web服务基于IP和域名部署
    Sentinel基础学习
    ARM-day2
    【操作系统】进程控制
    骗子查询系统源码
    基于Python+Pygame实现一个俄罗斯方块小游戏【完整代码】
  • 原文地址:https://blog.csdn.net/weixin_44257023/article/details/126041685