随笔分类 - spring boot
spring boot
摘要:这也是rest api相对高级用法,也就是URL里面没有动词,都是用put,get,delete,post(replace),patch表示动作 在使用Spring boot 开发restful 风格的项目,put、delete方法不起作用,解决办法。 实体类Student @Data public
阅读全文
摘要:logging: level: root:debug 可以打印所有日志,包括启动日志,这样就知道在哪里报错。假如启动失败的话,就可以在报错的地方设置断点进行调试,从而定位到启动失败原因。 也可以打印某一个jar包下面的日志,比如spring security: logging: level: roo
阅读全文
摘要:在使用spring boot集成多个微服务的时候,由于每个微服务使用orm框架不同,有的用mybatis,有的用mybatis-plus,有的用jpa,导致启动微服务失败。是因为被依赖的微服务使用jpa,而依赖别人的微服务使用mybatis,在applicationContext.xml文件中没有定
阅读全文
摘要:如果要添加接口校验,需要 第一步,在接口方法或者类方法中请求参数前面添加@Valid(来自jakarta.validation-api-2.0.2里面的类)或者@Validated注解,也可以在接口的实现类上添加@Valid注解,但不需要@Validated注解,如果校验失败,会反馈到Errors类
阅读全文
摘要:spring boot国际化使ReloadableResourceBundleMessageSource设置basenames并返回messagesource @Configuration public class I18nConfig { @Bean(name = "messageSource")
阅读全文
摘要:@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes={HelloService.impl}) //这样每个测试方法完成的时候就不会重复重启springboot
阅读全文
摘要:我们在启动 SpringBoot 时,控制台会打印 SpringBoot Logo 以及版本信息;这个操作是 SpringBoot 固定的还是可配置(自定义)的? . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '
阅读全文
摘要:在之前的《使用jsp作为视图模板&常规部署》章节有过一个实践,需要启动类继承自SpringBootServletInitializer方可正常部署至常规tomcat下,其主要能够起到web.xml的作用。下面通过源码简单解析为何其能够替代web.xml。 本章概要 1、源码分析如何实现SpringB
阅读全文
摘要:WebMvcConfigurationAdapter在spring boot2.0新版本中已经被废弃了,因为WebMvcConfigurationAdapter中的默认实现方法已经在它的父类中实现了。新版本spring boot是基于jdk8实现的,所以支持在接口中添加默认实现方法。 springb
阅读全文
摘要:注意:Springboot的版本是2.0.5.release。 Springboot中我们引入spring-boot-starter-web依赖后,web就自动配置好了,在web.xml的年代,我们需要在web.xml中手动配置DispatcherServlet,但是Springboot中不需要,S
阅读全文
摘要:概述SpringBoot 摒弃了繁琐的 xml 配置的同时,提供了几种注册组件:ServletRegistrationBean,FilterRegistrationBean,ServletListenerRegistrationBean,DelegatingFilterProxyRegistrati
阅读全文
摘要:方式一: 默认的application启动,在创建项目时自动生成application启动类,直接run执行即可。 方式二:使用外置的tomcat启动 默认的启动类要继承SpringBootServletInitiailzer类,并复写configure()方法。 @SpringBootApplic
阅读全文
摘要:mvc spring.mvc.async.request-timeout=设定async请求的超时时间,以毫秒为单位,如果没有设置的话,以具体实现的超时时间为准,比如tomcat的servlet3的话是10秒. spring.mvc.date-format=设定日期的格式,比如dd/MM/yyyy.
阅读全文
摘要:【1】SpringBoot的默认错误处理 ① 浏览器访问 请求头如下: ② 使用“PostMan”访问 { "timestamp": 1529479254647, "status": 404, "error": "Not Found", "message": "No message availabl
阅读全文
摘要:目录 1. 创建应用上下文 2. DefaultResourceLoader 3. AbstractApplicationContext 4. GenericApplicationContext 4.1 SimpleAliasRegistry 4.2 DefaultSingletonBeanRegi
阅读全文
摘要:测试代码: package com.github.abel533.event; import com.github.abel533.C; import org.springframework.context.ApplicationEvent; import org.springframework.c
阅读全文
摘要:1、前言简单介绍 SpringBoot的自动配置就是SpringBoot的精髓所在;对于SpringBoot项目是不需要配置Tomcat、jetty等等Servlet容器,直接启动application类既可,SpringBoot为什么能做到这么简捷?原因就是使用了内嵌的Servlet容器,默认是使
阅读全文
摘要:方法1:将SecurityContextHolder的策略更改为MODE_INHERITABLETHREADLOCAL 方法2:将上面的方法用java方法实现 方法3:AsyncTaskExecutor包装在DelegatingSecurityContextAsyncTaskExecutor中,该D
阅读全文