SpringBoot系列 创建项目和项目结构-已阅

本文介绍了如何使用IntelliJ IDEA和Spring Initializr创建SpringBoot项目,讨论了项目结构,包括SpringBoot起步依赖、启动类和打包插件。文章还提到了排除Tomcat并引入Jetty作为替代容器,并预告了接下来会详细讲解配置文件。
摘要由CSDN通过智能技术生成

创建SpringBoot

Idea创建项目,new Spring Initializr 、dependencies处选web、选springweb、上面有springboot版本可以选,要是找不到想要的版本,后面改也行。

除了pom和src其他都可以先删掉。

spring官网也可以创建,projects,overview,springboot,最下面quickstart your project,左边和idea一样,右边点击add dependencies,输入spring web进行搜索,把结果选中,最后点击generate。

项目结构:

SpringBoot起步依赖:

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

<!-- springboot对要用到的第三方框架都配置了适配版本,以后就不用纠结了。-->

        <parent>        

                <groupId>org.springframework.boot</groupId>        

                <artifactId>spring-boot-starter-parent</artifactId>        

                <version>2.5.0</version>    

        </parent>    

        <dependencies>        

                <dependency>            

                        <groupId>org.springframework.boot</groupId>            

                        <artifactId>spring-boot-starter-web</artifactId>  

                        <!--如果不想用tomcat容器,排除Tomcat起步依赖-->        

                        <exclusions>            

                                <exclusion>                

                                        <groupId>org.springframework.boot</groupId>                                                         <artifactId>spring-boot-starter-tomcat</artifactId>                                             </exclusion>        

                        </exclusions>      

                </dependency>    

                <!--添加Jetty起步依赖,版本由SpringBoot的starter控制。Jetty比Tomcat更轻量级,可扩展性更强(相较于Tomcat),谷歌应用引擎(GAE)已经全面切换为Jetty-->    

                <dependency>        

                        <groupId>org.springframework.boot</groupId>        

                        <artifactId>spring-boot-starter-jetty</artifactId>    

                </dependency>

   

                <dependency>            

                        <groupId>org.springframework.boot</groupId>            

                        <artifactId>spring-boot-starter-test</artifactId>            

                        <scope>test</scope>        

                </dependency>    

        </dependencies>

</project>

启动类:

@SpringBootApplication

public class SpringbootApplication {    

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

        }

}

打包插件和jar执行命令

打包插件

<build>    

        <plugins>        

                <plugin>            

                        <groupId>org.springframework.boot</groupId>            

                        <artifactId>spring-boot-maven-plugin</artifactId>        

                </plugin>    

        </plugins>

</build>

jar执行命令,由maven插件打出来的包指定了启动文件,以及要用到的所有jar包。

java –jar xxx.jar

配置文件

properties、yml或yaml,下一篇详细将。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呀吼呀吼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值