
SpringBoot
Spring注解介绍Spring基本知识
三侠剑
技术狂人
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
接口设置允许跨域访问
@CrossOrigin原创 2023-06-20 10:51:42 · 730 阅读 · 0 评论 -
actuator防止外部访问漏洞修复
解决办法适用于2.x springboot版本法零:和网站设置不同端口,不映射到外面,并修改路径法一:禁用所有http接口,将配置改成:management.endpoints.web.exposure.exclude=*法二:引入spring-boot-starter-security依赖,增加安全认证<dependency> <groupId>org.springframework.boot</groupId> <artifactId&...原创 2021-03-07 21:12:14 · 5831 阅读 · 0 评论 -
Convert理解_第一弹:HttpMessageConverter,GenericConverter,Converter,Formatter
HttpMessageConverter 简单说就是HTTP request (请求)和response (响应)的转换器 ,当请求和响应时,根据MediaType 顺序选择注册的合适的类别的HttpMessageConverter对数据进行处理。GenericConverter Converter 都是 数据转换类,系统初始化时注册到FormatterRegistry 类,对请求的参数进行类别转换,比如 字符串转为日期,字符串转为listFormatterRegistry是一个用于注...原创 2020-12-27 22:20:28 · 1163 阅读 · 0 评论 -
SpringBoot配置FeignClient打印请求日志
一、Feign原生方式配置(原文:https://blog.csdn.net/cen776727328/article/details/101273190)1、创建Feign的配置文件,并在其中设置日志等级@Configurationpublic class FeignConfiguration { @Bean Logger.Level feignLoggerLevel() { //这里记录所有,根据实际情况选择合适的日志level return原创 2020-12-25 00:48:51 · 11202 阅读 · 1 评论 -
理顺常用日志框架Commons-logging,slf4j,log4j,logback
Commons-loggin:是apache最早提供的日志的门面接口SLF4j:是Simple Logging Facade for Java的简称,即java的简单日志门面。类似于Apache Common-Logging,是对不同日志框架提供的一个门面封装,他在编译时静态绑定真正的Log库Log4j:通过使用Log4j,我们可以控制日志信息输送的目的地,是真正的实现日志输出的具体实现logback:也是一种日志实现。Logback是由log4j创始人设计的又一个开源日记组件,LogBack被原创 2020-08-12 14:56:53 · 368 阅读 · 0 评论 -
Spring Security ,Spring Actuator添加登录认证
一、继承WebSecurityConfigurerAdapter@Configuration(proxyBeanMethods = false)public class ActuatorSecurity extends WebSecurityConfigurerAdapter {}二、 配置限制1. 不认证@Overrideprotected void configure(HttpSecurity http) throws Exception { ...原创 2020-09-28 00:47:10 · 4432 阅读 · 0 评论 -
Druid集成实战
Druid介绍:https://www.iteye.com/magazines/90#1111. 引用依赖 <!-- mybatis --> <mybatis.spring.boot.starter.version>2.0.0</mybatis.spring.boot.starter.version> <mybatis.spring.version>2.0.0</mybatis.spring.version> &原创 2020-09-19 22:31:55 · 336 阅读 · 0 评论 -
ApplicationContextAware获取spring上下文
1. 获取到ApplicationContextpublic class MySource extends XXSource implements ApplicationContextAware { private ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContext) thro...原创 2020-09-16 23:10:38 · 186 阅读 · 0 评论 -
Swagger接口注解注释,接口定义为中文
1. 接口注解为中文@Api(value = "接口定义", description = "相关接口" , tags={"****接口"})@RestControllerpublic class XXController extends XXPController implements XXFacade2.方法注解@ApiOperation(value = "**详情/基本信息", httpMethod = "GET", produces = "application/json",...原创 2020-09-16 10:35:25 · 3297 阅读 · 0 评论 -
spring实现跨域的几种方式
1.@CrossOrigin 注解在controller层,加注解@CrossOrigin从4.2版开始,SpringMVC支持CORS。在springboot应用程序中使用带有@CrossOrigin注释的控制器方法CORS配置不需要任何特定的配置。需要明确请求方式,get,post2. 全局设置全局CORS配置可以通过使用定制的addCorsMappings(CorsRegistry)方法注册@Configuration(proxyBeanMethods = false) .原创 2020-09-14 21:14:59 · 521 阅读 · 0 评论 -
spring boot 配置 spring.config.location
1 . 2.x版本 spring.config.location 设置后,只读取这个文件配置内容,不再读取其他地址的配置文件 根据官方文档表述,默认会读取 1. file:./config/2. file:./config/*/3. file:./4. classpath:/config/5. classpath:/在使用spring.config.location指定外部配置文件时,需要此份配置文件需全量满足当前工程运行时所需,因为它不会...原创 2020-09-05 23:26:33 · 17615 阅读 · 0 评论 -
使用Actuator 在运行时改变日志等级
/loggers endpointloggersendpoint,可以通过访问http://localhost:8080/actuator/loggers来进入。它展示了应用中可配置的loggers的列表和相关的日志等级。你同样能够使用http://localhost:8080/actuator/loggers/{name}来展示特定logger的细节。举个例子,为了获得rootlogger的细节,你可以使用http://localhost:8080/actuator/loggers/roo..原创 2020-09-03 23:37:27 · 819 阅读 · 0 评论 -
spring-boot-starter-actuator (健康监控)配置和使用
spring-boot-starter-actuator(健康监控)配置和使用在生产环境中,需要实时或定期监控服务的可用性。Spring Boot的actuator(健康监控)功能提供了很多监控所需的接口,可以对应用系统进行配置查看、相关功能统计等。集成:<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-start...翻译 2020-09-02 21:51:41 · 16847 阅读 · 0 评论 -
SpringBoot支持的Web容器及相应的AccessLog配置
SpringBoot内置支持的Web容器有Tomcat、Undertow、Jetty和Netty,默认情况下,这些Web服务的Access日志是不开启的如果我们想开启这些日志,需要作如下配置:1,Tomcat容器日志配置SpringBoot 2.x默认支持的是Tomcat Web容器,如果我们想开启Access日志,只需要添加若干配置文件即可:server: tomcat: basedir: /var/tmp background-processor-delay.转载 2020-08-20 23:46:28 · 1057 阅读 · 0 评论 -
MDC介绍 -- 一种多线程下日志管理实践方式
一:MDC介绍 MDC(Mapped Diagnostic Context,映射调试上下文)是 log4j 和 logback 提供的一种方便在多线程条件下记录日志的功能。某些应用程序采用多线程的方式来处理多个用户的请求。在一个用户的使用过程中,可能有多个不同的线程来进行处理。典型的例子是 Web 应用服务器。当用户访问某个页面时,应用服务器可能会创建一个新的线程来处理该请求,也可能从线程池中复用已有的线程。在一个用户的会话存续期间,可能有多个线程处理过该用户的请求。这使得比较难以区分不同用户所对应的转载 2020-08-12 20:24:13 · 2429 阅读 · 0 评论 -
springboot整合 @Cache和Redis
原文链接:https://www.cnblogs.com/wenjunwei/p/10779450.htmlspring基于注解的缓存对于缓存声明,spring的缓存提供了一组java注解:@Cacheable:触发缓存写入。 @CacheEvict:触发缓存清除。 @CachePut:更新缓存(不会影响到方法的运行)。 @Caching:重新组合要应用于方法的多个缓存操作。 @CacheConfig:设置类级别上共享的一些常见缓存设置。@Cacheable注解顾名思义,@Cach转载 2020-09-19 22:45:35 · 195 阅读 · 0 评论 -
Actuator 过滤掉env,prop敏感信息
Information returned by the env and configprops endpoints can be somewhat sensitive so keysmatching a certain pattern are sanitized by default (i.e. their values are replaced by ******).The patterns to use can be customized using the management.endpoint.原创 2020-10-07 11:47:18 · 1638 阅读 · 0 评论 -
springboot替换tomcat
switching to a different HTTP server, you need to exclude the default dependencies inaddition to including the one you need. To help with this process, Spring Boot provides a separatestarter for each of the supported HTTP servers.<properties> &l原创 2020-10-05 20:32:06 · 966 阅读 · 0 评论 -
springboot配置随机数
my.secret=random.valuemy.number={random.value}my.number=random.valuemy.number={random.int}my.bignumber=random.longmy.uuid={random.long}my.uuid=random.longmy.uuid={random.uuid}my.number.less.than.ten=random.int(10)my.number.in.range={random.int(10)}my.原创 2020-09-25 19:54:45 · 890 阅读 · 0 评论 -
@value注意事项
If you do want to use @Value, we recommend that you refer to property names using their canonicalform (kebab-case using only lowercase letters). This will allow Spring Boot to use the same logic asit does when relaxed binding @ConfigurationProperties. Fo原创 2020-09-10 09:02:38 · 385 阅读 · 0 评论 -
Spring Framework反射型文件下载漏洞(CVE-2020-5421)解决方案
一、综述近日,VMware Tanzu发布安全公告,公布了一个存在于Spring Framework中的反射型文件下载(Reflected File Download,RFD)漏洞CVE-2020-5421。CVE-2020-5421 可通过jsessionid路径参数,绕过防御RFD攻击的保护。先前针对RFD的防护是为应对 CVE-2015-5211 添加的。攻击者通过向用户发送带有批处理脚本扩展名的URL,使用户下载并执行文件,从而危害用户系统。官方已发布修复了漏洞的新版本。二、影响范围原创 2020-10-22 16:11:10 · 4698 阅读 · 0 评论 -
改变springboot属性文件分隔符
You also need to include the following element inside <plugins/>:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.7</version&...转载 2020-10-04 22:19:00 · 1421 阅读 · 0 评论 -
Application Events and Listeners
Some events are actually triggered before the ApplicationContext is created, so you cannot register a listener on those as a @Bean. You can register them with the SpringApplication.addListeners(…) method or the SpringApplicationBuilder.listeners(…) method.转载 2020-10-04 21:36:10 · 173 阅读 · 0 评论 -
SpringBoot实现定时任务的三种方式
一,可以有3种方式配置定时任务Timer TimerTaskQuartz SchedulerTask Execution and Scheduling二, Quartz Scheduler(配置较为复杂) 1. 引用依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-qua...原创 2020-10-04 14:28:14 · 1390 阅读 · 0 评论 -
SpringBoot Actuator配置及指标
一、actuator 配置二 、actuator 首页http://localhost:19988/duno/ph/insp/ 查看所有链接{"_links":{"self":{"href":"http://localhost:19988/duno/ph/insp","templated":false},"archaius":{"href":"http://localhost:19988/duno/ph/insp/archaius","templated":false},"beans":{.原创 2020-09-29 22:56:03 · 1622 阅读 · 0 评论 -
Spring装配Converter,GenericConverter的过程
话不多说,上代码WebMvcConfigurationSupport /** * Return a {@link FormattingConversionService} for use with annotated controllers. * <p>See {@link #addFormatters} as an alternative to overriding this method. */ @Bean public Fo...原创 2020-09-28 21:33:23 · 469 阅读 · 0 评论 -
@Controller @RestController 区别
@RestController 中的方法不需要加@ResponseBody@Controller 需要原创 2020-09-26 23:22:13 · 101 阅读 · 0 评论 -
@ConfigurationProperties配置及注意事项
1. 加载方式@ConfigurationProperties(prefix = "another") @Bean public AnotherComponent anotherComponent() { ... }@ConfigurationProperties("acme") public class AcmeProperties {}2 .Binding MapsWhen binding to Map properties, if the key contains.原创 2020-09-25 22:58:40 · 2851 阅读 · 0 评论 -
spring bean 依赖注入标签 构造器注入
you can add @ComponentScan without any arguments. All of your application components ( @Component, @Service, @Repository, @Controller etc.) are automatically registered as Spring BeansThe following example shows a @Service Bean that uses constructor i.原创 2020-09-02 23:02:24 · 426 阅读 · 0 评论 -
Spring boot 官网文档
https://docs.spring.io/spring-boot/docs/2.3.3.RELEASE/reference/htmlsingle/原创 2020-09-02 22:37:23 · 1806 阅读 · 0 评论 -
HttpMessageConverter原理,SpringBoot用FastJsonHttpMessageConverter替换默认的HttpMessageConverters
1. springboot 默认使用JacksonSpring Boot provides integration with three JSON mapping libraries: • Gson • Jackson • JSON-B Jackson is the preferred and default library. 2. 为什么要替换为fastjsonjackson 的key 默认忽略大小写,我们在requestmapping中实际需要返回真正的key值..原创 2020-09-12 18:47:50 · 5752 阅读 · 0 评论 -
Spring boot 去掉自动加载的(@EnableAutoConfiguration )类的两种方式
1. @SpringBootApplication(exclude={DataSourceAutoConfiguration.class})2.配置文件中增加spring.autoconfigure.exclude原创 2020-09-02 22:44:48 · 2984 阅读 · 0 评论 -
@Configuration(proxyBeanMethods = false) 详解
1. Full 模式 Lite 模式proxyBeanMethods = true 或不写,是Full模式proxyBeanMethods = false 是lite模式不带@Configuration的类叫Lite配置类ConfigurationClassUtils2.@Configuration配置类是有主次之分的,主配置类是驱动整个程序的入口,可以是一个,也可以是多个(若存在多个,支持使用@Order排序)3.Full模式下通过方法调用指向的仍旧是原来的Bean..原创 2020-09-17 23:26:11 · 31414 阅读 · 9 评论 -
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration原创 2020-09-02 23:04:15 · 88 阅读 · 0 评论 -
@ConditionalOnExpression用法
@ConditionalOnExpression("'true")当括号中的内容为true时,使用该注解的类被实例化。框架中的用法:@ConditionalOnExpression("${****.enabled:false}")@Componentpublic class ***Job extends AbstractJob {针对 测试和生产环境可配置不同的值,如本地环境不需要起用job运行...原创 2020-08-20 17:33:25 · 26774 阅读 · 0 评论