Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewbednarski/cf334f3f4c8103375f94 to your computer and use it in GitHub Desktop.
Save matthewbednarski/cf334f3f4c8103375f94 to your computer and use it in GitHub Desktop.
An example for a Spring Boot Application which overrides the default servlet registration
import org.glassfish.jersey.servlet.ServletContainer;
import org.glassfish.jersey.servlet.ServletProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.DispatcherServlet;
/**
SpringBootNoDispatcherServlet.java SpringBootServletRegistrationOverrides.java Created by matthew.bednarski on 19/06/2015.
*/
@SpringBootApplication
public class Application {
@Bean
public FilterRegistrationBean securityFilterChainRegistration() {
DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy();
delegatingFilterProxy.setTargetBeanName(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME);
FilterRegistrationBean registrationBean = new FilterRegistrationBean(delegatingFilterProxy);
registrationBean.setName(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME);
registrationBean.addUrlPatterns("/*");
return registrationBean;
}
@Bean public ServletRegistrationBean jerseyServlet() {
ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(), "/rest/*");
// our rest resources will be available in the path /rest/*
registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, JerseyConfig.class.getName());
return registration;
}
@Bean
public ServletRegistrationBean dispatcherServlet(){
ServletRegistrationBean registration = new ServletRegistrationBean(new DispatcherServlet(), "/spring/*");
return registration;
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment