gpt4 book ai didi

Bean is expected to be of type CorsFilter but was actually of type UrlBasedCorsConfigurationSource with Spring Security 6(Bean应为CorsFilter类型,但实际上是具有Spring Security 6的UrlBasedCorsConfigurationSource类型)

转载 作者:bug小助手 更新时间:2023-10-26 21:25:32 35 4
gpt4 key购买 nike



I want to disable CORS for my frontend written in Angular, running locally on port 4200. I created a config but it doesn't seem to work.

我想禁用我的前端写在Angular的CORS,运行在本地端口4200上。我创建了一个配置,但它似乎不工作。


I get this error with Spring Security 6 after trying to start the application:

在尝试启动应用程序后,我在使用Spring Security6时收到以下错误:


Bean named 'corsFilter' is expected to be of type 
'org.springframework.web.filter.CorsFilter' but was actually of type
'org.springframework.web.cors.UrlBasedCorsConfigurationSource'

I'm following this answer and this Spring guide.

我正在遵循这个答案和这本春季指南。


My pom.xml

公司简介


<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>6.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>6.1.0</version>
</dependency>

My security config

我的安全配置


@Bean
public SecurityFilterChain configureSecurity(HttpSecurity http) throws Exception {
http
// ...
.cors(withDefaults());
return http.build();
}

@Bean
public CorsConfigurationSource corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.setAllowedOrigins(List.of("https://localhost:4200"));
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);

return source;
}

What's wrong? I use bean of type CorsConfigurationSource like they advice to me and Spring still wants CorsFilter like it was in previous versions of Spring Security?

怎么了?我使用CorsConfigurationSource类型的Bean,就像他们给我的建议一样,而Spring仍然想要CorsFilter,就像在Spring Security的以前版本中一样?


更多回答
优秀答案推荐

Rename corsFilter to corsConfigurationSource.

CorscorsFilter到CorscorationSource。


更多回答

similar to stackoverflow.com/a/77074993/7769052

类似于Stackoverflow.com/a/77074993/7769052

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com