springboot入门必备

229 阅读1分钟

idea快速创建一个springboot项目并跑起来

《今天开始学/复习springboot》

  1. 环境搭建(自己搭)
  2. File->New Project->Spring Initializr:Project SDK:选择你的jdk (我的1.8),chose initializr Service URL选择 defult
  3. ->next 默认就行,起名字的随便写
  4. 三个包:
    1. Spring Boot的版本仲裁中心,控制了所有依赖的版本号
    <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.2.1.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    1. 一个正常springboot项目启动,依赖的基础包:
    <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>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    
  5. appliciation.properity->ctrl+F6 改名:appliciation.yml
    配置如下:
    server:
        port: 8080
        servlet:
            context-path: /
    
  6. 启动xxxAppliciation  Path:src/main/java/com.xxx.xxx包下找到main启动即可