java - Spring boot 选择了错误的 CorsFilter

标签 java spring spring-boot

我正在开发一个具有安全功能的 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/

相关文章:

java - 为什么这些不同的数字是相同的?

java - 使用 UTCOffset 解析日期字符串

java - 从 hibernate 中获取查询的执行时间

java - 具有可配置约束值的 Spring Bean 验证

java - TomCat:创建类路径资源中定义的名称为 'requestMappingHandlerAdapter' 的 bean 时出错

java - 为什么即使对于开箱即用的 Spring Boot 管理员,Java 进程的 RES 内存也会保持缓慢增长?

java - jsp utf编码

spring - 如何将 "a-b"查询映射到 Spring MVC 中的命令对象

java - 在 spring boot 中重新加载/刷新缓存

java - 在应用程序运行时更新 Spring Boot 属性的更好方法