'Access-Control-Allow-Origin' with spring boot
JUST ADD DevConfiguration in any package then update application.properties file
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@Profile("development")
public class DevConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS").allowedOrigins("*");
}
}
Update application.properties file
# application.properties
spring.profiles.active=development
server.port=8090
Try adding this to your application:
@SpringBootApplication
@RestController
public class ChrisboltonServiceApplication {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*");
}
};
}
...
Also, try removing the crossDomain: true
from the $.ajax()
.