E
E
Eka22016-06-19 09:16:29
Spring
Eka2, 2016-06-19 09:16:29

What is the correct way to forward all requests in Spring?

There is a SpringApplication created by the designer, without the WEB_INF folder and settings in xml.
Can you please tell me how to correctly redirect all requests to static/index.html, except for those whose processing is registered in the controller?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor Alenkov, 2016-06-19
@Borz

like this (not sure about prioritization over other ViewControllers):

import org.springframework.core.Ordered;
@Configuration
public class CustomSpringConfiguration extends WebMvcConfigurerAdapter {
  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addRedirectViewController("/*", "/static/index.html");
    registry.setOrder(Ordered.LOWEST_PRECEDENCE);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question