[bs-141] Add Bootstrap WebApplicationInitializer got traditional wars

[#50806851] [bs-141] First class escape hatch from jar to war for web applications
This commit is contained in:
Dave Syer 2013-06-01 14:43:02 +01:00
parent 7e3c158f3a
commit 3c34326208
3 changed files with 63 additions and 0 deletions

View File

@ -219,6 +219,10 @@
<artifactId>maven-exec-plugin</artifactId>
<version>1.2.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>

View File

@ -68,6 +68,10 @@ public class ServerProperties {
this.address = address;
}
public void setLoader(String value) {
// no op
}
public static class Tomcat {
private String accessLogPattern;

View File

@ -0,0 +1,55 @@
package org.springframework.bootstrap.web;
import javax.servlet.Filter;
import org.springframework.util.ClassUtils;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.FrameworkServlet;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
/**
* <p>
* A handy opinionated {@link WebApplicationInitializer} for applications that only have
* one Spring servlet, and no more than a single filter (which itself is only enabled when
* Spring Security is detected). If your application is more complicated consider using
* one of the other WebApplicationInitializers.
* <p>
*
* <p>
* Note that a WebApplicationInitializer is only needed if you are building a war file and
* deploying it. If you prefer to run an embedded container (we do) then you won't need
* this at all.
* </p>
*
* @author Dave Syer
*
*/
public abstract class BootstrapServletInitializer extends
AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Override
protected Filter[] getServletFilters() {
if (ClassUtils.isPresent(
"org.springframework.security.config.annotation.web.EnableWebSecurity",
null)) {
DelegatingFilterProxy filter = new DelegatingFilterProxy(
"springSecurityFilterChain");
filter.setContextAttribute(FrameworkServlet.SERVLET_CONTEXT_PREFIX
+ "dispatcher");
return new Filter[] { filter };
}
return new Filter[0];
}
}