springboot 2.6.13WebMvcConfigurer和WebSecurityConfigurerAdapter都生效

时间: 2024-03-25 08:32:54 浏览: 12
根据提供的引用内容,可以看出在Spring Boot 2.6.13中,可以通过配置`spring.mvc.pathmatch.matching-strategy`来指定路径匹配策略。而在第一个引用中,配置的是`ant_path_matcher`策略,而在第二个引用中,也是配置的相同的策略。 因此,可以得出结论,在Spring Boot 2.6.13中,无论是WebMvcConfigurer还是WebSecurityConfigurerAdapter都会生效,并且都会使用`ant_path_matcher`作为路径匹配策略。
相关问题

springboot 2.6.13WebMvcConfigurer和WebSecurityConfigurerAdapter 实现方法都生效

根据提供的引用内容,可以使用Spring Boot 2.6.13中的WebMvcConfigurer和WebSecurityConfigurerAdapter来实现方法的生效。 首先,我们需要创建一个类,实现WebMvcConfigurer接口,并重写addInterceptors方法。在该方法中,我们可以添加自定义的拦截器。 ```java @Configuration public class MyWebMvcConfigurer implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { // 添加自定义的拦截器 registry.addInterceptor(new MyInterceptor()); } } ``` 接下来,我们需要创建一个类,继承WebSecurityConfigurerAdapter,并重写configure方法。在该方法中,我们可以配置安全相关的设置,例如身份验证和授权。 ```java @Configuration @EnableWebSecurity public class MyWebSecurityConfigurer extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { // 配置安全相关的设置 http.authorizeRequests() .antMatchers("/admin/**").hasRole("ADMIN") .antMatchers("/user/**").hasRole("USER") .anyRequest().authenticated() .and() .formLogin(); } } ``` 最后,我们需要在应用程序的入口类上添加@EnableWebMvc和@EnableWebSecurity注解,以启用WebMvcConfigurer和WebSecurityConfigurerAdapter。 ```java @SpringBootApplication @EnableWebMvc @EnableWebSecurity public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } } ``` 通过以上步骤,我们可以同时实现WebMvcConfigurer和WebSecurityConfigurerAdapter中的方法生效。

springboot2.6.13如何 WebMvcConfigurer和WebSecurityConfigurerAdapter实现方法同时生效

在Spring Boot 2.6.13中,可以通过实现WebMvcConfigurer和WebSecurityConfigurerAdapter接口来同时生效WebMvcConfigurer和WebSecurityConfigurerAdapter的配置方法。 下面是一个示例代码,展示了如何实现这两个接口并使其同时生效: ```java @Configuration @EnableWebMvc public class WebConfig implements WebMvcConfigurer { // 实现WebMvcConfigurer接口的方法 @Override public void addInterceptors(InterceptorRegistry registry) { // 添加拦截器 registry.addInterceptor(new MyInterceptor()); } } @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { // 实现WebSecurityConfigurerAdapter接口的方法 @Override protected void configure(HttpSecurity http) throws Exception { // 配置安全规则 http.authorizeRequests() .antMatchers("/admin/**").hasRole("ADMIN") .antMatchers("/user/**").hasRole("USER") .anyRequest().authenticated() .and() .formLogin().permitAll() .and() .logout().permitAll(); } } ``` 在上面的示例中,WebConfig类实现了WebMvcConfigurer接口的addInterceptors方法,用于添加拦截器。SecurityConfig类继承了WebSecurityConfigurerAdapter类,并重写了configure方法,用于配置安全规则。 为了使这两个配置同时生效,需要在启动类上添加@EnableWebMvc和@EnableWebSecurity注解,示例如下: ```java @SpringBootApplication @EnableWebMvc @EnableWebSecurity public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 这样,WebMvcConfigurer和WebSecurityConfigurerAdapter的配置方法就会同时生效。

相关推荐

最新推荐

recommend-type

Idea打包springboot项目没有.original文件解决方案

主要介绍了Idea打包springboot项目没有.original文件解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
recommend-type

qt usb 系统自检

LINUX2.6.13内核下是没有USB插拔机制的,即便是2.6.24内核依旧没有解决好USB插拔通知问题,而QT在版本4之前的版本都没有USB类的,没有USB插拔通知的方法,在QT4之后有了QDBUS,可通过QDBUS,进行USB热插拔
recommend-type

FreeNAS 开发人员手册

2.6.13 scponly 2.6.14 openssh-portable with HPN patch 2.6.15 ntfs-3g 2.6.16 e2fsck 2.6.17 SMART 2.6.18 aaccli 2.6.19 beep 2.6.20 mDNSReponder (Apple bonjour) 2.7 构建boot loader 3.8 添加库 ...
recommend-type

智能家居的项目用的 V4L2

以前做的智能家居的项目用的是Linux2.6.13的核,使用的中星微的摄像头,移植了spcaview进行图像的获取,后来用了2.6.29的核,发现以前移植的spcaview不能用了,后来查了一下,发现2.6.29核采用了UVC的驱动(万能驱动...
recommend-type

微信小程序-番茄时钟源码

微信小程序番茄时钟的源码,支持进一步的修改。番茄钟,指的是把工作任务分解成半小时左右,集中精力工作25分钟后休息5分钟,如此视作种一个“番茄”,而“番茄工作法”的流程能使下一个30分钟更有动力。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

解释minorization-maximization (MM) algorithm,并给出matlab代码编写的例子

Minorization-maximization (MM) algorithm是一种常用的优化算法,用于求解非凸问题或含有约束的优化问题。该算法的基本思想是通过构造一个凸下界函数来逼近原问题,然后通过求解凸下界函数的最优解来逼近原问题的最优解。具体步骤如下: 1. 初始化参数 $\theta_0$,设 $k=0$; 2. 构造一个凸下界函数 $Q(\theta|\theta_k)$,使其满足 $Q(\theta_k|\theta_k)=f(\theta_k)$; 3. 求解 $Q(\theta|\theta_k)$ 的最优值 $\theta_{k+1}=\arg\min_\theta Q(
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。