29 lines
1.1 KiB
Java
29 lines
1.1 KiB
Java
package com.baeldung.config;
|
|
|
|
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 javax.servlet.ServletException;
|
|
import javax.servlet.ServletRegistration;
|
|
|
|
public class WebInitializer implements WebApplicationInitializer {
|
|
@Override
|
|
public void onStartup(javax.servlet.ServletContext servletContext) throws ServletException {
|
|
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
|
context.register(DataSourceConfig.class);
|
|
context.register(ThemeMVCConfig.class);
|
|
|
|
|
|
servletContext.addListener(new ContextLoaderListener(context));
|
|
servletContext.setInitParameter("spring.profiles.active", "database");
|
|
|
|
ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
|
|
|
|
servlet.setLoadOnStartup(1);
|
|
servlet.addMapping("/");
|
|
|
|
}
|
|
}
|