Spring Boot 学习

Spring Boot 工程简单创建

  1. 工程创建
    New project -> New Module -> select 'Spring Initializr' and JDK 1.8
    Project Metadata: packaging Jar/War
    Dependencies: Web
  2. 工程编辑
    自动生成启动类
    在启动类下面创建一个子包,SpringMVC 的处理器类。
@RestController
public class SomeController {
      @RequestMapping("/some")
      public String someHandle(){
             return "Hello Spring Boot world";
}
}
  1. 启动运行
  2. 访问
    Jar: localhost:8080/some
    War: localhost:8080/some, 部署到tomact: localhost:8080/02-primarywar-1.0.0/test/some
    官网创建:https://start.spring.io

SpringBoot

  1. 主配置文件
  • 编辑器

Spring Boot 的主配置文件是 src/main/resources 中默认创建的 spring.properties 文件。该文件打开后是没有自动提示功能的。此时可以打开 Project Structure 窗口,在 Modules 中选中没有自动提示的工程,点击+号,找到 Spring,将其添加可以。此时的配置文件就有了自
动提示功能,包括后面的 yml 文件也有了自动提示。
访问: localhost:8888/xxx/test/some

application.properties
server.port=8888
server.servlet.context-path=/xxx
application.yml
server:
    port: 9999
    servlet:
        context-path: /xxx
     compression:
         enabled: true
         min-response-size: 2048
      tomact:
          uri-encoding: utf-8
  • Actuator 监控器

  • SpringBoot实现过滤器、拦截器与切片

  • springboot中自定义异常以及定制异常界面

  • SpringBoot多环境选择

  • 自定义配置文件

  • Spring Boot 中使用 MyBatis

  • Spring Boot 的事务支持

  • Spring Boot 对日志的控制

  • SpringBoot整合Redis

  • SpringBoot整合RabbitMQ

  • springboot+mybatis+mybaits plus 整合与基本应用

  • Spring Boot 中 Dubbo 的整合应用

  • Spring Boot 中使用 Servlet

  • 自定义 Starter 依赖

模板引擎 Thymeleaf

  • 什么是Thymeleaf
  • 模版引擎Thymeleaf怎么使用

Spring Boot 源码解析

  • @SpringBootApplication
    (1) 元注解
    前四个是专门(即只能)用于对注解进行注解的,称为元注解。
    @Target
    @Retention
    @Documented
    @Inherited:表示注解会被自动继承。
    (2) @SpringBootConfiguration
    (3) @ComponentScan
    (4) @EnableXxx
    A、配置类
    @Import 中指定的类一般为 Configuration 结尾,且该类上会注解@Configuration,表示当前类为 JavaConfig 类
    B、 选择器
    @Import 中指定的类一般以 Selector 结尾,且该类实现了 ImportSelector 接口,表示当前类会根据条件选择导入不同的类。
    C、 注册器
    @Import 中指定的类一般以 Registrar 结尾,且该类实现了 ImportBeanDefinitionRegistrar接口,用于导入注册器,该类可以在代码运行时动态注册指定类的实例。

  • 解析@EnableAutoConfiguration
    (1) @Import
    (2) @AutoConfigurationPackage

你可能感兴趣的:(Spring Boot 学习)