17

Trying to figure out what the equivalent @Bean configuration would be for the XML element

<mvc:view-controller path="..." />

Thanks!

dardo
  • 4,870
  • 4
  • 35
  • 52

1 Answers1

28

An example of forwarding a request for "/" to a view called "home" in Java:

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("home");
  }

}

And the same in XML use the element:

<mvc:view-controller path="/" view-name="home"/>

The above example was copied from the Spring reference docs

matsev
  • 32,104
  • 16
  • 121
  • 156
  • Exactly what I was looking for, knew it was in the documentation somewhere, must have skipped over it! Thanks a bunch! – dardo Jun 11 '13 at 16:50