[bs-141] Add Bootstrap WebApplicationInitializer got traditional wars

[#50806851] [bs-141] First class escape hatch from jar to war for web applications
pull/2/merge
Dave Syer 12 years ago
parent 7e3c158f3a
commit 3c34326208

@ -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>

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

@ -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];
}
}
Loading…
Cancel
Save