Я использую следующие технологии:
-Ява 8
-Пружина (boot 2, безопасность)
-Реагировать, axios
Кот 9
-IntelijIdea
В моем проекте я использую следующие методы http: GET, POST, PUT, PATCH и другие. У меня есть CORS configuratin. При запуске моего проекта в среде разработки или при тестировании методов в Postman -> CORS работает отлично. Однако когда я собираю файл war и запускаю его на сервере Tomcat, метод PATCH отказывается работать. (ОШИБКА: путь метода не разрешен методами access-control-allow-method в ответе перед полетом). Пожалуйста, помогите, чтобы исправить это.
Конфигурация безопасности:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable()
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.headers().frameOptions().sameOrigin()
.and()
.authorizeRequests()
.antMatchers("/",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js",
"/static/**",
"/static/css/*",
"/static/js/*",
"/*.js",
"/*.json",
"/*.ico"
).permitAll()
.antMatchers(SIGN_UP_URLS).permitAll()
.antMatchers(H2_URL).permitAll()
.anyRequest().authenticated()
;
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
}
Конфигурация CORS:
@Bean
public CorsConfigurationSource corsConfigurationSource() {
final CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("*"));
configuration.setAllowedMethods(Arrays.asList("HEAD",
"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
configuration.setAllowCredentials(true);
configuration.setAllowedHeaders(Arrays.asList("*"));
configuration.setExposedHeaders(Arrays.asList("X-Auth-Token","Authorization","Access-Control-Allow-Origin","Access-Control-Allow-Credentials"));
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}