随笔分类 -  Spring / Spring Boot

1
摘要:设置用户名、密码 1、配置文件 (1)application.properties #用户名 spring.security.user.name= #密码 spring.security.user.password= (2)application.yaml spring: security: use 阅读全文
posted @ 2022-06-23 18:16 半条咸鱼 编辑
摘要:Spring Boot 启动过程 1、示例 @SpringBootApplication public class MainApplication { public static void main(String[] args) { SpringApplication.run(MainApplica 阅读全文
posted @ 2022-06-22 15:32 半条咸鱼 编辑
摘要:Profiles 1、隔离应用程序配置部分,并使其仅在特定环境中可用 2、任何 @Component 或 @Configuration 都可以用 @Profile 标记以限制何时加载 3、默认配置文件 application.yaml,任何时候都会加载 4、指定环境配置文件 application- 阅读全文
posted @ 2022-06-21 21:53 半条咸鱼 编辑
摘要:Spring Boot Actuator 1、将应用程序推送到生产环境时,监控和管理应用程序,可以选择使用 HTTP 端点或 JMX 来管理和监视应用程序,审核,运行状况和指标收集也可以自动应用到应用程序 2、引入依赖 <dependency> <groupId>org.springframewor 阅读全文
posted @ 2022-06-21 17:51 半条咸鱼 编辑
摘要:JUnit5 1、Spring Boot 2.2.0 版本开始引入 JUnit 5 作为单元测试默认库 2、JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage (1)JUnit Platform:在 JVM 上启动测试框架的基础,不仅支持 阅读全文
posted @ 2022-06-21 00:32 半条咸鱼 编辑
摘要:SQL 1、自动配置数据库连接池 (1)带 data 的启动器,都与数据访问相关 (2)导入 JDBC 场景 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-j 阅读全文
posted @ 2022-06-20 18:27 半条咸鱼 编辑
摘要:Web 原生组件注入 1、使用嵌入式 Servlet 容器时,可以使用 Spring beans 或扫描 Servlet 组件,从 Servlet 规范中注册 Servlet,Filter、Listener 2、使用Servlet API(建议) (1)@ServletComponentScan(b 阅读全文
posted @ 2022-06-19 01:29 半条咸鱼 编辑
摘要:默认规则 1、默认情况下,Spring Boot 提供 /error 处理所有错误的映射 2、对于机器客户端,它将生成JSON响应,其中包含错误,HTTP状态和异常消息的详细信息 3、对于浏览器客户端,响应一个“ whitelabel”错误视图,以 HTML 格式呈现相同的数据 4、要对其进行自定义 阅读全文
posted @ 2022-06-18 15:06 半条咸鱼 编辑
摘要:页面设置表单标签 1、示例 <form method="post" action="/upload" enctype="multipart/form-data"> <input type="file" name="files" multiple/><br/> <input type="file" n 阅读全文
posted @ 2022-06-17 16:59 半条咸鱼 编辑
摘要:概述 1、拦截器需要实现 HandlerInterceptor 接口,或继承 HandlerlnterceptorAdapter 类(已弃用) 2、作用:SpringMVC 中的拦截器用于拦截控制器方法的执行 3、拦截器相当于原生 Servlet 过滤器(Filter) HandlerInterce 阅读全文
posted @ 2022-06-16 22:41 半条咸鱼 编辑
摘要:基本语法 1、表达式 名称 语法 作用 变量取值 ${...} 获取请求域、Session 域、对象等值 选择变量 *{...} 获取上下文对象值 消息 #{...} 获取国际化等值 链接 @{...} 生成链接 片段表达式 ~{...} 引入公共页面片段 2、字面量 (1)文本值:使用 '' 括住 阅读全文
posted @ 2022-06-15 21:38 半条咸鱼 编辑
摘要:概述 1、Spring Boot 处理请求,完成后跳转到指定页面的过程 2、视图处理方式 (1)转发 (2)重定向 (3)自定义视图 3、Spring Boot 打包方式为 jar,JSP 不支持在压缩包内编译,需要引入第三方模板引擎技术实现页面渲染 4、Spring Boot 可引入的第三方模板引 阅读全文
posted @ 2022-06-15 21:37 半条咸鱼 编辑
摘要:响应 JSON 1、引入 Web 场景启动器 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> (1)自动引入 阅读全文
posted @ 2022-06-15 02:14 半条咸鱼 编辑
摘要:RESTful 风格 1、@RequestMapping (1)支持 RESTful 风格:使用 HTTP 请求方式动词来表示对资源的操作 (2)核心 Filter:HiddenHttpMethodFilter (3)派生注解:@GetMapping、@PostMapping、@PutMapping 阅读全文
posted @ 2022-06-13 23:31 半条咸鱼 编辑
摘要:Spring MVC 自动配置 1、Spring Boot 为 Spring MVC 提供了自动配置,适用于大多数应用程序 2、自动配置在 Spring 的默认值之上添加了以下功能 (1)包含 ContentNegotiatingViewResolver(内容协商视图解析器)和 BeanNameVi 阅读全文
posted @ 2022-06-12 00:27 半条咸鱼 编辑
摘要:文件类型 1、properties 2、yaml YAML 1、标记语言 2、基本语法 (1)key: value (2)冒号之后需要一个空格 (3)大小写敏感 (4)使用缩进表示层级关系 (5)缩进不允许使用 Tab,只允许空格 (6)缩进的空格数不重要,只要相同层级的元素左对齐即可 (7)# 表 阅读全文
posted @ 2022-06-10 12:19 半条咸鱼 编辑
摘要:步骤 1、引入场景依赖:选择 Spring Boot / 第三方的 starter 2、查看自动配置 (1)application.properties 配置文件中,debug=true 开启自动配置报告 (2)Negative matches:以下自动配置类不生效);Positive matche 阅读全文
posted @ 2022-06-10 02:56 半条咸鱼 编辑
摘要:SpringBoot2 引导加载自动配置类 1、@SpringBootApplication <=> @SpringBootConfiguration + @EnableAutoConfiguration + @ComponentScan 2、@SpringBootConfiguration:底层为 阅读全文
posted @ 2022-06-09 22:11 半条咸鱼 编辑
摘要:@Import({DBHelper.class}) @Configuration(proxyBeanMethods = false) public class MyConfig { @Bean("User") public User user01(){ User user = new User("z 阅读全文
posted @ 2022-06-09 16:56 半条咸鱼 编辑
摘要:Maven 工程 1、引入依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.0</version> </pa 阅读全文
posted @ 2022-06-08 18:22 半条咸鱼 编辑

1
点击右上角即可分享
微信分享提示