deployment descriptor in java

This commit is contained in:
Eugen 2013-05-22 14:50:48 +03:00
parent 34c89649fe
commit 38361e887f
3 changed files with 43 additions and 2 deletions

View File

@ -120,7 +120,7 @@
<properties>
<!-- Spring -->
<org.springframework.version>3.2.2.RELEASE</org.springframework.version>
<org.springframework.version>3.2.3.RELEASE</org.springframework.version>
<!-- logging -->
<org.slf4j.version>1.7.5</org.slf4j.version>
@ -132,7 +132,7 @@
<mockito.version>1.9.5</mockito.version>
<httpcore.version>4.2.4</httpcore.version>
<httpclient.version>4.2.4</httpclient.version>
<httpclient.version>4.2.5</httpclient.version>
<rest-assured.version>1.8.0</rest-assured.version>
<groovy.version>1.8.9</groovy.version>

View File

@ -0,0 +1,41 @@
package org.baeldung.spring.web.config;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class MainWebAppInitializer implements WebApplicationInitializer {
/**
* Register and configure all Servlet container components necessary to power the web application.
*/
@Override
public void onStartup(final ServletContext sc) throws ServletException {
System.out.println("GreenhouseWebAppInitializer.onStartup()");
// Create the 'root' Spring application context
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
root.scan("org.baeldung.spring.web.config");
// root.getEnvironment().setDefaultProfiles("embedded");
// Manages the lifecycle of the root application context
sc.addListener(new ContextLoaderListener(root));
// Handles requests into the application
final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
appServlet.setLoadOnStartup(1);
final Set<String> mappingConflicts = appServlet.addMapping("/");
if (!mappingConflicts.isEmpty()) {
throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
}
}
}