Skip to content

Instantly share code, notes, and snippets.

@maggandalf
Forked from anonymous/ServletContext.java
Created June 20, 2011 09:00
Show Gist options
  • Save maggandalf/1035336 to your computer and use it in GitHub Desktop.
Save maggandalf/1035336 to your computer and use it in GitHub Desktop.
Servlet Context configuration using Java-based container configuration.
/**
* DispatcherServlet Context: defines this servlet's request-processing infrastructure
*/
@Configuration
//Enables the Spring MVC @Controller programming model
@EnableWebMvc
//Imports user-defined @Controller beans that process client requests.
@Import({Controller.class})
public class ServletContextConfig extends WebMvcConfigurerAdapter {
/**
* Requests for /resources/** are mapped to files in ${webappRoot}/resources.
*/
@Override
public void configureResourceHandling(ResourceConfigurer configurer) {
configurer.addPathMapping("/resources/**");
configurer.addResourceLocation("/resources/");
}
/**
* Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory
* @return cofigured InternalResourceViewResolver view Resolver.
*/
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
internalResourceViewResolver.setPrefix("/WEB-INF/views/");
internalResourceViewResolver.setSuffix(".jsp");
return internalResourceViewResolver;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment