gpt4 book ai didi

java - Spring boot 选择了错误的 CorsFilter

转载 作者:行者123 更新时间:2023-12-01 23:30:10 24 4
gpt4 key购买 nike

我正在开发一个具有安全功能的 Spring Boot Web 应用程序。我依赖于一个带有我需要使用的自定义 Cors 过滤器的库,但我的应用程序不断选择 Spring Web Framework Cors 过滤器并呈现以下错误:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.5.RELEASE:run (default-cli) on project tools-services: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'corsFilter' is expected to be of type 'org.springframework.web.filter.CorsFilter' but was actually of type 'com.myproj.sample.inf.sec.filter.CorsFilter' -> [Help 1]

我正在尝试在我的 Application.java 类中创建一个 CorsFilter bean,如下所示:

@Bean
public CorsFilter corsFilter() {
return new CorsFilter();
}

但是,这给了我同样的错误。有没有办法让 Spring Boot 指向自定义 cors 过滤器或禁用​​ spring cors 过滤器?

最佳答案

可能是因为同名。您可以尝试更改 Application.java 中使用的 bean 名称吗?

关于java - Spring boot 选择了错误的 CorsFilter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58293008/

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