Created
May 14, 2014 13:08
-
-
Save kknd22/d925557d54ddb940265c to your computer and use it in GitHub Desktop.
webapplicationinitializer example
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
/** | |
http://stackoverflow.com/questions/17370176/webapplicationinitializer-is-not-launched-on-jettyselenium | |
*/ | |
public class WebappConfig implements WebApplicationInitializer { | |
protected final Logger logger = LoggerFactory.getLogger(getClass()); | |
@Override | |
public void onStartup(final ServletContext servletContext) throws ServletException { | |
if(logger.isDebugEnabled()) { | |
logger.debug("Starting web context configuration"); | |
} | |
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); | |
// rootContext.getEnvironment().setActiveProfiles("production"); | |
rootContext.register(SpringConfig.class, SpringSecurityConfig.class, SpringWebConfig.class, SpringJNDIDataConfig.class, SpringJNDIJPAConfig.class); | |
servletContext.addListener(RequestContextListener.class); | |
new ContextLoader(rootContext).initWebApplicationContext(servletContext); | |
addFilters(servletContext, rootContext.getEnvironment()); | |
servletContext.setInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME, ConfigurationUtil.config().getString("jsf.stage")); | |
servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", ConfigurationUtil.config().getString("jsf.refreshPeriod")); | |
} | |
private void addFilters(final ServletContext servletContext, final ConfigurableEnvironment configurableEnvironment) { | |
FilterRegistration.Dynamic securityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")); | |
securityFilter.addMappingForUrlPatterns(null, false, "/*"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment