-
-
Save maggandalf/1035336 to your computer and use it in GitHub Desktop.
Servlet Context configuration using Java-based container configuration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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