- 一、创建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
通过idea工具创建工程时,不再选择maven了而是选择spring initializr。然后去勾选相关依赖。
- 如果默认网址不行可以换https://start.aliyun.com/
点击Finish之后,生成的文件、目录如下。
1.pom- 该项目的
是spring-boot-starter-parent; - 项目默认添加了两个依赖spring-boot-starter-web、pring-boot-starter-test;
2.目录结构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
- 自动给我们构建好test;
- 测试类使用的注解是SpringBootTest;
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
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下的注解;
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的方式。
- 注入了两个类型均为ThreadPoolExecutor的Bean;
- 方法的参数是MessagePullAllExecutorConfig(里面有值);
SpringBoot集成@Slf4j:
http://t.csdn.cn/Hc1QO



