1.创建一个springboot工程

本文详细介绍了如何使用SpringBoot创建一个简单的项目,包括创建启动类、配置application.yml文件中的服务器端口和数据库连接,以及在pom.xml中添加必要的依赖。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建一个springboot工程的内容,项目自己建。

1.创建一个springboot项目

 2.Application

package com.lpc;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @Author lpc
 * @Date 2024 01 05 10 13
 * <p>
 * springboot项目启动类
 * <p>
 *
 * @SpringBootApplication 它的作用是将当前类标识为 Spring Boot 应用的入口点,并启用自动配置和组件扫描。
 *
 * @Slf4j 在这里就是这个作用 log.info("项目启动成功。。。。。");
 * @Slf4j 用于自动为类生成一个名为 “log” 的日志对象。它是 Lombok 项目中提供的一个注解,通过在类上添加 @Slf4j 注解,
 * 可以方便地在代码中使用日志记录功能。
 * 
 **/


@SpringBootApplication
@Slf4j
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
        log.info("项目启动成功。。。。。");
    }
}

3.application.yml

server:
  port: 8001
spring:
  #连接数据库
  datasource:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/数据库名?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
      username: root
      password: 密码

4.pom.xml

 <!--它是 Spring Boot 应用程序的父项目,可以继承 Spring Boot 的默认参数、
    默认配置和依赖管理,简化了项目的构建和配置工作。-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.5.RELEASE</version>
    </parent>


 <properties>
        <!--依赖版本控制-->
        <lombok.version>1.18.16</lombok.version>
    </properties>



<dependencies>

        <!--spring boot相关依赖-->

        <!--这个依赖项是 Spring Boot 的核心依赖,它包含了一系列常用的 Spring Boot 模块和库。
        这个依赖项主要用于构建 Spring Boot 应用程序,它封装了许多常用的配置和依赖项,使得开发者
        可以更快速地搭建和启动一个基于 Spring Boot 的项目。-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <!--是用于编写测试代码的 Spring Boot 依赖项,它包含了一些常用的测试框架和工具。
        这个依赖项的 scope 被设为 test,表示这些依赖项仅在测试阶段需要使用,不会被包含到最终的构建结果中。-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--这个依赖项是用于开发基于 Spring Boot 的 Web 应用程序的。它提供了一些基本的依赖项和配置,
                以帮助你快速搭建一个 Web 应用程序。-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <scope>compile</scope>
        </dependency>

        <!--Lombok 是一个开发工具,可以通过注解自动化生成 Java 代码中的一些样板代码,
        如 getter、setter、构造函数等,减少了编写冗余代码的工作量。-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
        </dependency>


        
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- 指定该Main Class为全局的唯一入口 这里是启动类的地址 -->
                    <mainClass>com.lpc.Application</mainClass>
                    <layout>ZIP</layout>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值