一键搭建SpringBoot项目

2022-04-11 08:54:23 浏览数 (1)

简介

都2020年了,你还在手动创建SpringBoot项目吗?今天教你在线快速创建一个SpringBoot项目,瞬间高大上有木有!

进入正题,首先打开创建SpringBoot的官网:https://start.spring.io/

①选择Project构建工具 -> Maven Project

②选择Language -> Java

③选择SpringBoot版本 -> 2.3.2当前稳定版本

④填入Project Metadata

Group:一般是倒域名【org.louis】

Artifact:项目名【blog】

Name:项目名【blog】

Description:描述【A popular online mall.】

Packaging:打包类型【Jar】,SpringBoot运行时的打包项目,一般SpringBoot都是打为Jar包,如果使用Tomcat容器的话就选择War包

Java:Java版本,主流项目选Java8,个人项目可以选择Java11进行测试

接下来是重点:引入依赖【Dependencies

这里推荐一些经常使用的依赖:

①Spring Web:Build web, including RESTful, applications using Spring MVC. Uses Apache Tomcat as the default embedded container.

②Spring Data JPA:Persist data in SQL stores with Java Persistence API using Spring Data and Hibernate.

③Spring Data Redis:Advanced and thread-safe Java Redis client for synchronous, asynchronous, and reactive usage. Supports Cluster, Sentinel, Pipelining, Auto-Reconnect, Codecs and much more.

④Spring Boot Actuator:Supports built in (or custom) endpoints that let you monitor and manage your application - such as application health, metrics, sessions, etc.

⑤MySQL Driver:MySQL JDBC and R2DBC driver.

⑥Java Mail Sender:Send email using Java Mail and Spring Framework's JavaMailSender.

⑦Thymeleaf:A modern server-side Java template engine for both web and standalone environments. Allows HTML to be correctly displayed in browsers and as static prototypes.

⑧Lombok:Java annotation library which helps to reduce boilerplate code.

再额外推荐一些常用的依赖:

代码语言:javascript复制
<!-- WebSocket -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- gson依赖 -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.2</version>
        </dependency>

        <!--依赖nekoHTML 1.9.15 or newer的版本  -->
        <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.22</version>
        </dependency>

        <!-- 支持 @ConfigurationProperties 注解 -->  
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-configuration-processor</artifactId>  
            <optional>true</optional>  
        </dependency>

        <!-- JWT  Token -->
        <dependency>  
            <groupId>io.jsonwebtoken</groupId>  
            <artifactId>jjwt</artifactId>  
            <version>0.6.0</version>  
        </dependency>

        <!-- 文件上传所依赖的jar包 -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>

        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.3</version>
        </dependency>

        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>4.5.10</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.zxing/core -->
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
            <version>3.1.0</version>
        </dependency>

        <!-- Swagger2-ui用于生成、描述、调用和可视化 RESTful 风格的 Web 服务 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

        <!-- alibabaJSON -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.58</version>
        </dependency>

        <!-- 实现跨服务器文件传输 -->
        <dependency>
          <groupId>com.jcraft</groupId>
          <artifactId>jsch</artifactId>
          <version>0.1.49</version>
        </dependency>

        <!-- Emoji表情 -->
        <dependency>
            <groupId>com.vdurmont</groupId>
            <artifactId>emoji-java</artifactId>
            <version>4.0.0</version>
        </dependency>

        <!--WebSocket作为Java客户端-->
        <dependency>
            <groupId>org.java-websocket</groupId>
            <artifactId>Java-WebSocket</artifactId>
            <version>1.3.5</version>
        </dependency>

        <!--compress压缩解压包-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <version>1.18</version>
        </dependency>

        <!-- ZeroMQ -->
        <dependency>
              <groupId>org.zeromq</groupId>
              <artifactId>jeromq</artifactId>
              <version>0.3.1</version>
        </dependency>

        <!-- @Transactional注解写在class上,就会导致InterceptorBinding类报错 -->
        <!-- 引入InterceptorBinding依赖, 启动不会报错,否则直接注解方法不会报错-->
        <dependency>
            <groupId>javax.interceptor</groupId>
            <artifactId>javax.interceptor-api</artifactId>
            <version>1.2</version>
        </dependency>

配置好之后,点击 EXPLORE 开始导出

在弹窗后点击 DOWNLOAD 开始下载

现在,一个完整的SpringBoot项目就创建好了!

解压出来用编辑器打开就可以开心的撸代码了!

0 人点赞