Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

spring enable cors

@Controller
@CrossOrigin(origins = "http://localhost:3000")
public class MyController {

}
Comment

spring security enable global cors

@Override
	public void configure(HttpSecurity http) throws Exception {
		http.cors().configurationSource(request -> new CorsConfiguration().applyPermitDefaultValues())
 		// ...
	}


	@Bean
	public WebMvcConfigurer corsConfigurer() {
		return new WebMvcConfigurer() {
			@Override
			public void addCorsMappings(CorsRegistry registry) {
				registry.addMapping("/**")
				.allowedOrigins("*")
				.allowedMethods("GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS");
			}
		};
	}
Comment

how to enable cors request on springboot application

package com.example.restservicecors;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
public class RestServiceCorsApplication {

	public static void main(String[] args) {
		SpringApplication.run(RestServiceCorsApplication.class, args);
	}

	@Bean
	public WebMvcConfigurer corsConfigurer() {
		return new WebMvcConfigurer() {
			@Override
			public void addCorsMappings(CorsRegistry registry) {
				registry.addMapping("/greeting-javaconfig").allowedOrigins("http://localhost:8080");
			}
		};
	}

}COPY
Comment

PREVIOUS NEXT
Code Example
Java :: calculate mean from arraylist jaca 
Java :: hashmap sort by value descending 
Java :: resource leak java 
Java :: get logged-in user in Spring Security 
Java :: localdate add months in java 
Java :: spring jpa count all rows 
Java :: encode file to base64 java 
Java :: spigot respawn player location 
Java :: check array is sorted java 
Java :: startactivityforresult deprecated android 
Java :: what is an error in java 
Java :: how to iterate hashmap java 
Java :: convert java to kotlin online editor 
Java :: how to know java version in cmd 
Java :: change height of row at JTable 
Java :: how to scan a string in java 
Java :: java program to print 1 to 100 using for loop 
Java :: conditions in for loop java 
Java :: java prime numbers 
Java :: area of circle in java 
Java :: how to format numbers in java 
Java :: Spring boot fix cors problem 
Java :: java convert LocalDateTime to long 
Java :: java remainder sign 
Java :: datetimeformatter for java 
Java :: how to minimize jframe in java 
Java :: get distance from latitude and longitude code android 
Java :: empty array java 
Java :: split string 2 characters java 
Java :: java max int value 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =