Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

spring enable cors

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

}
Comment

Spring boot fix cors problem

@Configuration
public class CorsConfig {

    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**").allowedMethods("GET", "POST", "PUT", "DELETE").allowedOrigins("*")
                        .allowedHeaders("*");
            }
        };
    }
}
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

CORS with Spring Boot

@CrossOrigin
Comment

PREVIOUS NEXT
Code Example
Java :: what is java plug-in 
Java :: java foreach 
Java :: delay a function call in java 
Java :: char array to arraylist java 
Java :: groovy ternary operator short form 
Java :: open gallery android 
Java :: how to get width android 
Java :: main methode java 
Java :: jframe actionlistener 
Java :: java find last element in array 
Java :: check instance of java 
Java :: initialize arraylist in 1 line in java 
Java :: how to call intent in adapter class in android 
Java :: initialize arraylist 
Java :: java return list 
Java :: android java xml combo box 
Java :: set remove element java 
Java :: convert date to offsetdatetime in java 
Java :: java File Separator 
Java :: int to byte 
Java :: Java for Keyword 
Java :: who created java 
Java :: string length solidity 
Java :: double to string java 
Java :: java dynamic method dispatch 
Java :: java float 0/0 
Java :: find number of occurrences of a substring in a string java 
Java :: java break multiple loops 
Java :: how to check if the file has remaining without reading from it java 
Java :: terminate a frame java 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =