spring boot 拦截器WebMvcConfigurerAdapter作用,以及高版本的替换方案

西门子S7-1200模拟量的使用 模块类型核心参数输入信号处理输出信号配置转换原理数值范围TIA Portal配置编程要点 转换公式: 输出模拟量: 五、校准与线性化 硬件校准非线性补偿抗干扰措施数字滤波温度控制压力监控流量调节信号异常精度不足实践操作参考文档项目案例借鉴博客 阅读详情

WebMvcConfigurerAdapter 的作用是:

  • 进行SpringMVC的一些配置、在Spring中,为了减少xml的配置,引入了@Configuration注解。
  • WebMvcConfigurerAdapter的出现是为了替代xml出现的,在这个类型里可以配置拦截器相关配置,这个类的使用是弱化繁杂xml配置的一个缩影,Adapter中文译作适配器,转换器,意思就是作为xml配置的一种适配,一种取代。

 

最近项目采用spring icloud,用的spring boot版本是1.5.x的,spring boot 2.0,Spring 5.0 以后WebMvcConfigurerAdapter会取消掉。以下介绍下大体的内容,希望对大家都有所帮助。

  • 以下WebMvcConfigurerAdapter 比较常用的重写接口

  • 新的版本解决方案目前有两种

    方案1 直接实现WebMvcConfigurer(官方推荐)

        @Configuration
    public class WebMvcConfg implements WebMvcConfigurer {
    
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                    registry.addViewController("/index").setViewName("index");
            }
    
    }

    方案2 直接继承WebMvcConfigurationSupport

        @Configuration
    public class WebMvcConfg extends WebMvcConfigurationSupport {
    
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                    registry.addViewController("/index").setViewName("index");
            }
    
    }
  • 其实,源码下WebMvcConfigurerAdapter是实现WebMvcConfigurer接口,所以直接实现WebMvcConfigurer接口也可以;WebMvcConfigurationSupport与WebMvcConfigurerAdapter、接口WebMvcConfigurer处于同一个目录下WebMvcConfigurationSupport包含WebMvcConfigurer里面的方法,由此看来版本中应该是推荐使用WebMvcConfigurationSupport类的,WebMvcConfigurationSupport应该是新版本中对WebMvcConfigurerAdapter的替换和扩展【个人见解,如果有误,请帮忙纠正】

     

/** 解决跨域问题 **/
public void addCorsMappings(CorsRegistry registry) ;
/** 添加拦截器 **/
void addInterceptors(InterceptorRegistry registry);
/** 这里配置视图解析器 **/
void configureViewResolvers(ViewResolverRegistry registry);
/** 配置内容裁决的一些选项 **/
void configureContentNegotiation(ContentNegotiationConfigurer configurer);
/** 视图跳转控制器 **/
void addViewControllers(ViewControllerRegistry registry);
/** 静态资源处理 **/
void addResourceHandlers(ResourceHandlerRegistry registry);
/** 默认静态资源处理器 **/
void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer);

 

@Configuration  
public class CorsConfig extends WebMvcConfigurerAdapter{

    @Override   
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT")
                .maxAge(3600);
    }
}

 

文章整理来自:

1、spring boot拦截器WebMvcConfigurerAdapter,以及高版本的替换方案

2、https://blog.youkuaiyun.com/qq_20314665/article/details/77700728

3、SpringBoot——》WebMvcConfigurerAdapter详解

【OpenClaw从入门到精通】第09篇:企业级实践——将OpenClaw接入钉钉,打造7×24小时数字员工(2026实测版) 本文聚焦OpenClaw的企业级落地实践,以“招聘数字专员”为核心场景,完整演示从钉钉接入到全流程自动化的实现路径。内容涵盖企业级部署架构设计、前置环境搭建、核心技能开发、流程串联、安全权限管控及运维监控六大模块,详解简历解析、岗位匹配、外呼集成、CRM同步、日历提醒等关键技能的构建逻辑与代码实现。借鉴中关村科金、网易智企的企业级实践经验,重点突破企业知识融合、安全权限管控、业务系统连接三大核心门槛,提供可直接参考的配置示例与操作步骤。所有技术方案均基于公开文档与实测验证,兼顾新手入门与进阶实操。 阅读详情

相关推荐

AGX Orin设计-外围电路设计之一

AGX ORIN是英伟达Jetson系列中算力规格最高端的模组,其高达200TOPS/275TOPS的算力可以为各类场景提供澎湃的算力支持,本篇文章针对AGX ORIN的常规外围电路设计做分析描述。

zhiyuchenkeji的博客 4488

springboot自定义静态资源代理WebMvcConfigurerAdapter详解和过期后的替代方案WebMvcConfigurer

1、什么是WebMvcConfigurerAdapter Spring内部的一种配置方式 采用JavaBean的形式来代替传统的xml配置文件形式进行针对框架个性化定制html 2、WebMvcConfigurerAdapter经常使用的方法 /** 解决跨域问题 **/ public void addCorsMappings(CorsRegistry registry) ; /** 添加拦截器 **/ void addInterceptors(InterceptorRegistry regist

tiger_Angle 1916

如何制作Mike21溢油模型围油栏文件

这段时间群友在做海洋环评的做了一个MIKE21的溢油模型,溢油模型其实也是ECOLAB模块的应用,而在海上发生溢油事件的时候,为防止溢油对海洋生态的破坏,经常使用的一种手段就是使用围油栏技术将溢油控制在一定范围并进行处理。今天小编就给大家说说在MIKE21里怎么实现围油栏文件的制作

zhuzhujiayoua的博客 1332

WebMvcConfigurerAdapter详解

一、WebMvcConfigurerAdapter是什么 Spring内部的一种配置方式 采用JavaBean的形式来代替传统的xml配置文件形式进行针对框架个性化定制 二、WebMvcConfigurerAdapter常用的方法 /** 解决跨域问题 **/ public void addCorsMappings(CorsRegistry registry) ; /** 添加拦截器 **...

caodongfang126的博客 9184

缠论 公式 自动画线 画笔 中枢 买卖点 源代码

【代码】缠论 公式 自动画线 画笔 中枢 买卖点 源代码。

weixin_40835859的博客 2万+

Livox MID-360与FAST-LIO2实战:从驱动部署到参数调优的完整指南

激光雷达惯性里程计(LIO)是机器人定位与建图(SLAM)领域的核心技术,它通过紧耦合融合激光雷达点云与惯性测量单元(IMU)数据,实现高精度、低漂移的位姿估计。其核心原理在于利用IMU的高频数据预测运动,并用激光雷达的精确测距信息进行校正与优化,从而在快速运动或特征缺失场景下保持鲁棒性。这项技术的工程价值在于为自动驾驶、移动机器人及三维重建提供了可靠的前端里程计解决方案。针对Livox MID-360固态雷达与FAST-LIO2这一热门组合,其应用场景广泛覆盖了室内外导航与地图构建。本文聚焦于**驱动部署

weixin_29997523的博客 448

WebMvcConfigurerAdapter的替换 WebMvcConfigurer接口和WebMvcConfigurationSupport继承类

在SpringBoot2.0以上已经将WebMvcConfigurerAdapter摒弃了。 替换使用WebMvcConfigurer接口或者WebMvcConfigurationSupport继承类。 但在使用时发现,若是继承WebMvcConfigurationSupport就会出现无法访问到静态资源的问题。 而采实现WebMvcConfigurer接口的方式则不会。 o.s.web...

weixin_42030522的博客 327

基于STM32与MPU6050的实时姿态检测系统设计与实现(源码+硬件解析)

本文详细介绍了基于STM32单片机与MPU6050传感器的实时姿态检测系统设计与实现。通过硬件解析、传感器校准、卡尔曼滤波算法和欧拉角计算,实现高精度姿态检测。提供完整源码和调试技巧,适用于无人机、平衡车等嵌入式开发项目,解决噪声干扰和数据漂移等常见问题。

jupi8的博客 497

Spring MVC的WebMvcConfigurerAdapter 作用

WebMvcConfigurerAdapter 的作用是进行SpringMVC的一些配置在Spring中,为了减少xml的配置,引入了@Configuration注解。Spring MVC的WebMvcConfigurerAdapter用法收集(零配置,无XML配置) https://www.cnblogs.com/EasonJim/p/7720095.html...

yinni11的博客 3419

高通thermal-engine.conf配置详解:从虚拟传感器到CPU频率控制的完整指南

本文深入解析了高通thermal-engine.conf配置文件的架构与调优方法。从虚拟传感器的加权融合原理,到监控算法与CPU频率控制的多级策略,提供了完整的配置详解与实战调试指南。文章旨在帮助开发者与高级用户掌握底层温控逻辑,在性能与散热间实现精准平衡,并详细介绍了日志调试与场景化配置等高级技巧。

weixin_28327051的博客 495

ADB详细(从下载安装到灵活运用)

ADB(Android Debug Bridge)是一种允许模拟器或已连接的 Android 设备进行通信的命令行工具,它可为各种设备操作提供便利,如安装和调试应用,并提供对 Unix shell(可用来在模拟器或连接的设备上运行各种命令)的访问。可以在Android SDK/platform-tools中找到 adb 工具或下载ADB Kits。

LiuYong_01的博客 10万+

WebMvcConfigurerAdapter

响应体写入:当控制器方法处理完请求并返回一个Java对象时,如果这个控制器方法使用了 @ResponseBody 注解标注,或者在Spring Boot中,由于默认已配置了 @RestController,MappingJackson2HttpMessageConverter 会自动将Java对象序列化为JSON格式的字符串,并将其写入HTTP响应体中。Java 8的接口默认方法使得这个过程变得更加简单,因为你不需要实现所有的方法,只需要重写你感兴趣的那些。

ruangongtaotao的专栏 1425

工商银行软件开发中心数据安全监测溯源防护体系建设成果及展望

结合业界先进溯源理念和我行管理要求,依托大数据、分布式搜索分析引擎等技术,构建PB级海量数据加工分析和小时级快速核验、检索、溯源手段(如图6所示),支撑6种客户敏感信息关键要素的单一或组合溯源,形成行之有效的数据安全溯源流程,配套落地自动化快速泄露样本真实性核验和灵活高效的溯源能力,通过数据相关属性的自动化分析,实现追踪泄露源头、明确泄露路径的目标,为有效应对数据安全事件,降低和消除风险与不良影响,开展事后追责处置工作提供体系化解决方案。提高数据排查的自动化程度和排查效率,降低人工成本。

银行信息系统应用架构详解 226

spring boot拦截器WebMvcConfigurerAdapter,以及高版本的替换方案

用的spring boot版本是1.5.x的,spring boot 2.0,Spring 5.0 以后WebMvcConfigurerAdapter会取消掉。以下介绍下大体的内容,希望对大家都有所帮助。 以下WebMvcConfigurerAdapter 比较常用的重写接口 /** 解决跨域问题 **/ public void addCorsMappings(CorsRegist...

k849875005的博客 230

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

WebMvcConfigurerAdapter 高版本的替换方案

转载自:《spring boot拦截器WebMvcConfigurerAdapter,以及高版本的替换方案》 最近项目采用spring icloud,用的spring boot版本是1.5.x的,spring boot 2.0,Spring 5.0 以后WebMvcConfigurerAdapter会取消掉。以下介绍下大体的内容,希望对大家都有所帮助。 以下WebMvcConfigur...

yh_zeng2的博客 1064

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Spring Boot拦截器 WebMvcConfigurerAdapter 高版本替换方案

Spring Boot拦截器 WebMvcConfigurerAdapter 高版本替换方案 高版本的替换方案目前有两种: 方案1 直接继承WebMvcConfigurationSupport @Configuration public class MvcConfig extends WebMvcConfigurationSupport { @Override ...

Hinbo的博客 556

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Spring Boot WebMvcConfigurerAdapter 实现拦截器无配置

SpringBoot对静态资源的支持以及很重要的一个类WebMvcConfigurerAdapter,该类可以省去我们之前的拦截XML配置文件,减少了对于XML文件的管理,这也是springBoot无配置的思想。 Spring Boot 默认为我们提供了静态资源处理,使用 WebMvcAutoConfiguration 中的配置各种属性。 首先创建对应的拦截器 这里我创建class

Edward_developer的专栏 1945

WebMvcConfigurerAdapter已过时,替换接口或类

WebMvcConfigurerAdapter已经过时,在新版本2.x中被废弃,原因是springboot2.0以后,引用的是spring5.0,而spring5.0取消了WebMvcConfigurerAdapter 以下WebMvcConfigurerAdapter 比较常用的重写接口 /** 解决跨域问题 **/ public void addCorsMappings(CorsR...

weixin_30478757的博客 1328

WebMvcConfigurerAdapter详解和过时后的替代方案(转载)

WebMvcConfigurer

qq_47155894的博客 1315

WebMvcConfigurerAdapter/HandlerInterceptorAdapter/FilterRegistrationBean

WebMvcConfigurerAdapter过时的替换方法 转自:https://blog.youkuaiyun.com/tyvbpq/article/details/83588508 Spring 5.0后,WebMvcConfigurerAdapter被废弃,取代的方法有两种: ①implements WebMvcConfigurer(官方推荐) ②extends WebMvcConfiguration...

西京刀客 2017

springboot——WebMvcConfigurerAdapter的替代

由于在使用WebMvcConfigurerAdapter类时会发现其已经过时,此时我们需要新的方案来代替。 第一种:实现WebMvcConfigurer接口 @Configuration public class WebMvcConfg implements WebMvcConfigurer { @Override public void addViewCo...

编码日常 1079

java中拦截器和过滤器详解

1 过滤器和拦截器的异同 1.1 一张图表明两者之间的差异: tomcat,filter,servet,interceptor以及controller等各种容器的关系图 1.2 两者的区别: 拦截器是基于java的反射机制的,而过滤器是基于函数回调。 拦截器不依赖与servlet容是依赖于spring容器,过滤器依赖与servlet容器。 拦截器只能对action请求起作用,而过滤器则可以对几乎所有的请求起作用,可以限制用户对图片,文件以及其他资源的访问。 拦截器可以访问action请求上

yxg520s的博客 7819
上一篇: Lvs+keepalived+Nginx双机热备实现Nginx高可用
下一篇: spring boot 过滤器 filter
AndyChen9988
博客等级 码龄11年 276粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值