gary69
gary69

Reputation: 4230

Spring CORS 404

I'm using spring mvc without spring security. I have this bean in my @Configuration class trying to allow requests from localhost:8080

@Bean
    @Profile("dev")
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**").allowedOrigins("http://localhost:8080").allowedMethods("GET","POST","PUT","DELETE", "OPTIONS");
            }
        };
    }

The active profile is dev in my application.yml. My application is running on localhost:8090. This request works http://localhost:8090/assessment/api/questions/page?offset=0&limit=10 but this request returns a 404 http://localhost:8080/assessment/api/questions/page?offset=0&limit=10

Am I missing some extra configuration?

Upvotes: 1

Views: 838

Answers (1)

DwB
DwB

Reputation: 38300

You are confusing URL to which to send the request and URL from which the request was sent.

"My application is running on localhost:8090." appears to indicate that the only listener you have is on port 8090.

CORS is a means to allow requests that source from a different domain, it is not a means to setup multiple listeners in your container.

Upvotes: 1

Related Questions