, чтобы «нет», чтобы принести ресурс с отключенными Cors. Когда мы сталкиваемся с ошибкой Cors. < /p>
Это моя настройка Cors в Spring Boot 3. < /p>
Код: Выделить всё
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.company.pack"})
@PropertySource("classpath:/app-${spring.profiles.active}.properties")
public class Config implements WebMvcConfigurer {
@Value("${allowed-origins:*}")
// this has https://www.company.com,https://company.com,https://sample.company.com
// printed via a PostConstruct just to confirm and prints correctly.
String allowedOriginsPattern;
@Override
public void addCorsMappings(CorsRegistry registry) {
String[] origins = allowedOriginsPattern.split(",");
registry.addMapping("/**")
.allowedOriginPatterns(origins)
.allowedMethods("GET", "OPTIONS", "POST")
.allowedHeaders(
"content-type",
..... other custom headers
)
.allowCredentials(true);
}
}
< /code>
также попробовал с < /p>
.allowedOrigins(origins)
Чего мне не хватает?
Подробнее здесь: https://stackoverflow.com/questions/795 ... rigin-list