|
24 | 24 | import org.springframework.util.ClassUtils;
|
25 | 25 | import org.springframework.web.cors.CorsConfiguration;
|
26 | 26 | import org.springframework.web.cors.CorsConfigurationSource;
|
| 27 | +import org.springframework.web.cors.PreFlightRequestHandler; |
27 | 28 | import org.springframework.web.filter.CorsFilter;
|
28 | 29 | import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
|
29 | 30 |
|
@@ -107,15 +108,14 @@ static class MvcCorsFilter {
|
107 | 108 | * @return
|
108 | 109 | */
|
109 | 110 | private static CorsFilter getMvcCorsFilter(ApplicationContext context) {
|
110 |
| - if (!context.containsBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME)) { |
111 |
| - throw new NoSuchBeanDefinitionException(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, "A Bean named " |
112 |
| - + HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME + " of type " |
113 |
| - + HandlerMappingIntrospector.class.getName() |
114 |
| - + " is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext."); |
| 111 | + if (context.getBeanNamesForType(CorsConfigurationSource.class).length > 0) { |
| 112 | + CorsConfigurationSource corsConfigurationSource = context |
| 113 | + .getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, CorsConfigurationSource.class); |
| 114 | + return new CorsFilter(corsConfigurationSource); |
115 | 115 | }
|
116 |
| - HandlerMappingIntrospector mappingIntrospector = context.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, |
117 |
| - HandlerMappingIntrospector.class); |
118 |
| - return new CorsFilter(mappingIntrospector); |
| 116 | + throw new NoSuchBeanDefinitionException(CorsConfigurationSource.class, |
| 117 | + "Failed to find a bean that implements `CorsConfigurationSource`. Please ensure that you are using " |
| 118 | + + "`@EnableWebMvc`, are publishing a `WebMvcConfigurer`, or are publishing a `CorsConfigurationSource` bean."); |
119 | 119 | }
|
120 | 120 |
|
121 | 121 | }
|
|
0 commit comments