Skip to content

Instantly share code, notes, and snippets.

@krams915
Created December 8, 2012 05:46
Show Gist options
  • Select an option

  • Save krams915/4238821 to your computer and use it in GitHub Desktop.

Select an option

Save krams915/4238821 to your computer and use it in GitHub Desktop.
Spring Social ApplicationInitializer.java
package org.krams.config;
import javax.servlet.FilterRegistration;
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.filter.DelegatingFilterProxy;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.servlet.DispatcherServlet;
public class ApplicationInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// Load application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(ApplicationContext.class);
rootContext.setDisplayName("Spring Social Tutorial");
// Add context loader listener
servletContext.addListener(new ContextLoaderListener(rootContext));
// Declare dispatcher servlet
ServletRegistration.Dynamic dispatcher =
servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
// Register Spring security filter
FilterRegistration.Dynamic springSecurityFilterChain =
servletContext.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class);
springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*");
// Register Spring Social filter so that we can disconnect from providers
FilterRegistration.Dynamic hiddenHttpMethodFilter =
servletContext.addFilter("hiddenHttpMethodFilter", HiddenHttpMethodFilter.class);
hiddenHttpMethodFilter.addMappingForUrlPatterns(null, false, "/*");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment