Created
August 26, 2015 07:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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