栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot项目详细创建步骤

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot项目详细创建步骤

目录标题
  • 一、创建springboot项目
    • (1)创建spring initializr工程
    • (2)勾选需要的的依赖
    • (3)项目结构如下
      • 1.pom
      • 2.目录结构
      • 3.测试类
    • (4)如何在springboot项目中添加测试
  • 二、SpringBoot读取application.properties文件中的值
    • (1)SpringBoot读取配置文件的方式
    • (2)application.properties配置如下
    • (3)SpringBoot集成lombok
    • (4)@ConfigurationProperties
    • (5)测试
  • 三、SpringBoot注入Bean
    • SpringBoot注入Bean的几种方式
    • @Configuration+@Bean的方式注入
  • 四、SpringBoot整合@Slf4j

一、创建springboot项目 (1)创建spring initializr工程

通过idea工具创建工程时,不再选择maven了而是选择spring initializr。然后去勾选相关依赖。

  • 如果默认网址不行可以换https://start.aliyun.com/

(2)勾选需要的的依赖

(3)项目结构如下

点击Finish之后,生成的文件、目录如下。

1.pom
  1. 该项目的 是spring-boot-starter-parent;
  2. 项目默认添加了两个依赖spring-boot-starter-web、pring-boot-starter-test;


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.6.7
         
    

    com.example
    spring-demo
    0.0.1-SNAPSHOT
    spring-demo
    spring-demo

    
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



2.目录结构
  1. 自动给我们构建好test;

3.测试类
  1. 测试类使用的注解是SpringBootTest;

(4)如何在springboot项目中添加测试

http://t.csdn.cn/Ph9rj

二、SpringBoot读取application.properties文件中的值 (1)SpringBoot读取配置文件的方式

1、读取application.properties文件中的值的方式:
https://blog.csdn.net/weixin_42344117/article/details/118087641
2、读取非application.properties文件中的值的方式:
https://blog.csdn.net/weixin_42344117/article/details/117605507

(2)application.properties配置如下
email.message.pull.all.executor.corePoolSize = 10
email.message.pull.all.executor.maximumPoolSize = 50
email.message.pull.all.executor.keepAliveTime = 5
email.message.pull.all.executor.workQueueCapacity = 500

(3)SpringBoot集成lombok

lombok更多使用方式:
https://blog.csdn.net/itCatface/article/details/119038565

引入lombok依赖:

       
        
            org.projectlombok
            lombok
            true
        

使用@Setter、@Getter注解的包是lombok,不是jdk.nashorn.internal.objects.annotations下的注解;

(4)@ConfigurationProperties
package com.example.springdemo.config.executor;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Setter
@Getter
@Component
@ConfigurationProperties(prefix = "email.message.pull.all.executor")
public class MessagePullAllExecutorConfig {
    private Integer corePoolSize;
    private Integer maximumPoolSize;
    private long keepAliveTime;
    private Integer workQueueCapacity;
}

(5)测试

三、SpringBoot注入Bean SpringBoot注入Bean的几种方式

https://blog.csdn.net/Smy_0114/article/details/122229852

我们采用:@Configuration+@Bean的方式。

@Configuration+@Bean的方式注入

  1. 注入了两个类型均为ThreadPoolExecutor的Bean;
  2. 方法的参数是MessagePullAllExecutorConfig(里面有值);
四、SpringBoot整合@Slf4j

SpringBoot集成@Slf4j:
http://t.csdn.cn/Hc1QO

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/854795.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号