Я использую Angular во внешнем интерфейсе и Java Spring во внутреннем, но я получаю сообщение об ошибке: No 'Access-Control-Allow-Origin' header is present on the requested resource.
, хотя я уверен, что CORS включен.Это мой файл конфигурации:
package com.aon04.backend.configuration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@EnableWebMvc
public class CorsConfiguration implements WebMvcConfigurer
{
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
}
И он работает, я могу выполнить любой другой запрос без проблем, но этот запрос PUT в моем сервисе выдает мне ошибку:
updateExamById(id, exam: Examen): Observable<Examen> {
return this.http.put<Examen>(APIURL + '/update/' + id, {file: exam.file, name: exam.naam});
}
Этомоя серверная часть:
@PutMapping("/update/{id}")
public Exam UpdateExam(@RequestParam("file") MultipartFile file, @RequestParam("name") String name, @PathVariable("id") int id)
{
Exam newExam = new Exam();
newExam.setId(id);
newExam.setSkelet(file.getOriginalFilename());
newExam.setNaam(name);
newExam.setCreatedAt(LocalDateTime.now());
Exam exam2 = ExamFactory.update(newExam);
examRepository.save(exam2);
storageService.store(file);
return newExam;
}