quick_start.md 3.5 KB

springboot-note

springboot 学习项目,

章节

  • spring-boot-actuator spring-boot-admin-simple spring-boot-banner spring-boot-commandLineRunner spring-boot-docker spring-boot-elasticsearch spring-boot-fastDFS spring-boot-file-upload spring-boot-helloWorld spring-boot-jpa spring-boot-jpa-thymeleaf-curd spring-boot-mail spring-boot-memcache-spymemcached spring-boot-mongodb spring-boot-mybatis spring-boot-mybatis-plus spring-boot-package spring-boot-package-war spring-boot-rabbitmq spring-boot-redis spring-boot-scheduler spring-boot-shiro spring-boot-swagger spring-boot-thymeleaf spring-boot-web spring-boot-web-thymeleaf spring-boot-webflux

springboot 项目初始化

Spring Boot Starter Parent 父级 pom 文件来统一管理版本依赖

<properties>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <resource.delimiter>@</resource.delimiter>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

spring-boot-devtools

热部署,无需重复重启项目。


<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>

Log4j2

Spring Boot 中默认使用 Logback 作为日志框架,我们需要知道的是 Log4j2 是 Log4j 的升级版。添加依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

log4j2.properties 配置文件:

status = error
name = Log4j2Sample
appenders = console

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} - %msg%n

rootLogger.level = warn
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT

代码中打印日志:

		LOG.debug("debug 级别日志 ...");
		LOG.info("info 级别日志 ...");
		LOG.warn("warn 级别日志 ...");
		LOG.error("error 级别日志 ...");
		LOG.fatal("fatal 级别日志 ...");

AOP

通过自定义注解的方式,在 Spring Boot 中来实现 AOP 切面统一打印出入参日志

<!-- aop 依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

<!-- 用于日志切面中,以 json 格式打印出入参 -->
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.5</version>
</dependency>

JPA

自动配置

AOP

数据库

mysql

redis

缓存: 文件,redis,EhCache

mongo

web,Restful,API,open api,

Thymeleaf

国际化

注解,控制器,

Reference

License