SpringBoot-01-helloSpring

164 阅读1分钟

创建SpringBoot项目

在官网start.spring.io/ 下载zip包后导入idea

直接在idea中创建(选择Spring Initializr进行创建)

项目结构

所有的包都需要建在主程序所在包的同级目录或之下

如:最初的包名为com.example.SpringBoot01,则所有的包应当建立在SpringBoot01下否则扫描不到

package com.example.SpringBoot01;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//程序主入口
@SpringBootApplication
public class SpringBoot01Application {

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

}
application。properties是Springboot项目的核心配置文件

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
    <!--Springboot项目的父项目-->
   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.4.3</version>
      <relativePath/> <!-- lookup parent from repository -->
   </parent>
   <groupId>com.example</groupId>
   <artifactId>SpringBoot-01</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>SpringBoot-01</name>
   <description>Demo project for Spring Boot</description>
   <properties>
      <java.version>1.8</java.version>
   </properties>
   <dependencies>
       <!--所有的springboot依赖以spring-boot-starter开头-->
      <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>
   </dependencies>
<!--   打包插件-->
   <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>

</project>

application.properties

#核心配置文件
#修改端口号
server.port=8081

修改启动图标

在resources下建立banner.txt,该文件中的信息会成为spring启动的图标