* Sample code for BAEL-1148 - earth001@gmail.com * Change tabs for spaces in non java files * Change tabs for spaces in non java files * Removed unnecessary argument
49 lines
2.0 KiB
Java
49 lines
2.0 KiB
Java
package com.baeldung.config;
|
|
|
|
import javax.servlet.ServletContext;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.ServletRegistration;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.web.WebApplicationInitializer;
|
|
import org.springframework.web.context.ContextLoaderListener;
|
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
|
import org.springframework.web.servlet.DispatcherServlet;
|
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|
|
|
@Configuration
|
|
@EnableWebMvc
|
|
@ComponentScan(basePackages = "com.baeldung.controller")
|
|
public class PushConfiguration implements WebApplicationInitializer, WebMvcConfigurer {
|
|
|
|
@Override
|
|
public void onStartup(ServletContext container) throws ServletException {
|
|
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
|
context.register(PushConfiguration.class);
|
|
container.addListener(new ContextLoaderListener(context));
|
|
ServletRegistration.Dynamic dispatcher = container.addServlet("DispatcherServlet", new DispatcherServlet(context));
|
|
dispatcher.setLoadOnStartup(1);
|
|
dispatcher.addMapping("/");
|
|
}
|
|
|
|
@Bean
|
|
public InternalResourceViewResolver jspViewResolver() {
|
|
InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
|
bean.setPrefix("/WEB-INF/views/");
|
|
bean.setSuffix(".jsp");
|
|
return bean;
|
|
}
|
|
|
|
@Override
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
registry.addResourceHandler("/resources/**")
|
|
.addResourceLocations("/resources/");
|
|
}
|
|
|
|
}
|