public class MyWebAppInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext container) { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebSpringConfig.class); // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(DispatcherConfig.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); } }
Stagemonitor.init(); if (ServletContainerInitializerUtil.avoidDoubleInit(this, ctx)) return; ctx.addServlet(ConfigurationServlet.class.getSimpleName(), new ConfigurationServlet()) .addMapping(ConfigurationServlet.CONFIGURATION_ENDPOINT); ctx.addServlet(StagemonitorMetricsServlet.class.getSimpleName(), new StagemonitorMetricsServlet()) .addMapping("/stagemonitor/metrics"); ctx.addServlet(ClientSpanServlet.class.getSimpleName(), new ClientSpanServlet()) .addMapping("/stagemonitor/public/eum"); final ClientSpanJavaScriptServlet servlet = new ClientSpanJavaScriptServlet(); Stagemonitor.getPlugin(ServletPlugin.class).setClientSpanJavaScriptServlet(servlet); ctx.addServlet(ClientSpanJavaScriptServlet.class.getSimpleName(), servlet) .addMapping("/stagemonitor/public/eum.js"); ctx.addServlet(StagemonitorFileServlet.class.getSimpleName(), new StagemonitorFileServlet()) .addMapping("/stagemonitor/static/*", "/stagemonitor/public/static/*"); ctx.addServlet(WidgetServlet.class.getSimpleName(), new WidgetServlet()) .addMapping("/stagemonitor"); final ServletRegistration.Dynamic spanServlet = ctx.addServlet(SpanServlet.class.getSimpleName(), new SpanServlet()); spanServlet.addMapping("/stagemonitor/spans"); spanServlet.setAsyncSupported(true); securityFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/stagemonitor/*"); securityFilter.setAsyncSupported(true); final ServletRegistration.Dynamic healthServlet = ctx.addServlet(HealthCheckServlet.class.getSimpleName(), new HealthCheckServlet(Stagemonitor.getHealthCheckRegistry())); healthServlet.addMapping("/stagemonitor/status"); healthServlet.setAsyncSupported(true);
@BeforeClass public static void startJettyServer() throws Exception { // Let server pick its own random, available port. jettyServer = new Server(0); ServletContextHandler handler = new ServletContextHandler(); MultipartConfigElement multipartConfig = new MultipartConfigElement(""); ServletHolder holder = new ServletHolder(partsServlet); holder.getRegistration().setMultipartConfig(multipartConfig); handler.addServlet(holder, "/parts"); holder = new ServletHolder(partListServlet); holder.getRegistration().setMultipartConfig(multipartConfig); handler.addServlet(holder, "/partlist"); jettyServer.setHandler(handler); jettyServer.start(); Connector[] connectors = jettyServer.getConnectors(); NetworkConnector connector = (NetworkConnector) connectors[0]; baseUrl = "http://localhost:" + connector.getLocalPort(); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { //Filter is needed to alter the urls used to serve patient specific URLs javax.servlet.FilterRegistration.Dynamic filter = servletContext.addFilter("dasFilter", new DasURLFilter()); if (filter == null) { LOG.warn("ServletContext already contains a complete FilterRegistration for servlet 'dasFilter'"); } else { filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/das/*"); } Dynamic dasServlet = servletContext.addServlet("dasServlet", new MydasServlet()); if (dasServlet == null) { LOG.warn("ServletContext already contains a complete ServletRegistration for servlet 'dasServlet'"); } else { dasServlet.setLoadOnStartup(1); dasServlet.addMapping("/das/*"); } } }
new AnnotationConfigWebApplicationContext()) { rootContext.register(ProbeConfig.class); servletContext.setInitParameter("attribute.value.roles", "ROLE_MANAGER,ROLE_MANAGER-GUI"); servletContext.addListener(new ContextLoaderListener(rootContext)); ServletRegistration.Dynamic probe = servletContext.addServlet("probe", ProbeServlet.class); probe.setInitParameters(initParameters); probe.setLoadOnStartup(0); probe.addMapping("*.htm"); probe.addMapping("*.ajax"); probe.addMapping("/logs/*"); probe.addMapping("/chart.png"); servletContext.addFilter("sitemesh", SiteMeshFilter.class); sitemesh.addMappingForUrlPatterns( EnumSet.of(DispatcherType.FORWARD, DispatcherType.REQUEST, DispatcherType.ERROR), false, "/*"); EnumSet<SessionTrackingMode> trackingMode = EnumSet.of(SessionTrackingMode.COOKIE); servletContext.setSessionTrackingModes(trackingMode);
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(appConfig); servletContext.addListener(new ContextLoaderListener(rootContext)); DispatcherServlet dispatcherServlet = new DispatcherServlet(rootContext); dispatcherServlet.setDispatchOptionsRequest(true); dispatcherServlet.setThrowExceptionIfNoHandlerFound(true); servletContext.addServlet("dispatcher", dispatcherServlet); if (dispatcherServletRegistration == null) { LOG.warn( } else { final long maxSize = (long) maxFileSize * MB; dispatcherServletRegistration.addMapping("/"); dispatcherServletRegistration.setMultipartConfig( new MultipartConfigElement(null, maxSize, maxSize, FILE_SIZE_THRESHOLD)); servletContext.addFilter("browserDetectionFilter", BrowserDetectionFilter.class); browserDetectionFiler.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "*"); Dynamic etagFilter = servletContext.addFilter("etagFilter", ShallowEtagHeaderFilter.class); etagFilter.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, "dispatcher");
public class WebInit implements WebApplicationInitializer { private static final String DISPATCHER_SERVLET_NAME = "spring-mvc"; private static final String DISPATCHER_SERVLET_MAPPING = "/"; @Override public void onStartup(ServletContext servletContext) throws ServletException { //If you want to use the XML configuration, comment the following two lines out. AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.register(CoreConfig.class); appContext.setDisplayName("removed customer name"); //If you want to use the XML configuration, uncomment the following lines. //XmlWebApplicationContext rootContext = new XmlWebApplicationContext(); //rootContext.setConfigLocation("classpath:mvc-servlet.xml"); AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(ServletConfig.class); ServletRegistration.Dynamic springmvc = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(mvcContext)); springmvc.setLoadOnStartup(1); springmvc.addMapping(DISPATCHER_SERVLET_MAPPING); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); security.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); servletContext.addListener(new ContextLoaderListener(appContext)); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(SpringMvcConfig.class); // 新建WebApplication,注册配置类,并将其和当前servletContext关联。 context.setServletContext(servletContext); // 注册SpringMVC的DispatcherServlet。 ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); servlet.addMapping("/"); servlet.setLoadOnStartup(1); // 注册SpringMVC的字符过滤器 FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encoding", new CharacterEncodingFilter()); EnumSet<DispatcherType> dispatcherTypes = EnumSet.allOf(DispatcherType.class); dispatcherTypes.add(DispatcherType.REQUEST); dispatcherTypes.add(DispatcherType.FORWARD); encodingFilter.addMappingForUrlPatterns(dispatcherTypes, true, "*"); encodingFilter.setInitParameter("encoding", "UTF-8"); }
// Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SecurityConfiguration.class); // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); dispatcherServlet.register(WebMvcConfiguration.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); // Register spring security FilterChain FilterRegistration.Dynamic registration = container.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR, DispatcherType.ASYNC); registration.addMappingForUrlPatterns(dispatcherTypes, true, "/*");
ServletRegistration.Dynamic provisioning = environment.servlets().addServlet("Provisioning", provisioningServlet); websocket.addMapping("/v1/websocket/"); websocket.setAsyncSupported(true); provisioning.addMapping("/v1/websocket/provisioning/"); provisioning.setAsyncSupported(true); filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); filter.setInitParameter("allowedOrigins", "*"); filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin,X-Signal-Agent"); filter.setInitParameter("allowedMethods", "GET,PUT,POST,DELETE,OPTIONS"); filter.setInitParameter("preflightMaxAge", "5184000");
@Override public void onInitialize(ServletContext servletContext, AnnotationConfigWebApplicationContext applicationContext) { ServletRegistration.Dynamic dispatcherServlet = servletContext .addServlet("Spring MVC Dispatcher Servlet", new DispatcherServlet(applicationContext)); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.addMapping("/*"); .addFilter("springSecurityFilterChain", new DelegatingFilterProxy( "springSecurityFilterChain", applicationContext)) .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); .addFilter("opensessioninview", OpenSessionInViewFilter.class) .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); .addServlet(SimplePostFilesStrategy.class.getName(), FileUploadServlet.class) .addMapping(SimplePostFilesStrategy.URL_PATTERN); .addListener(new ContextLoaderListener(applicationContext));
@Override public void initialize(final ServerCoreComponents coreComponents) { final Configuration configuration = coreComponents.getConfiguration(); final ServletContext servletContext = coreComponents.getInstance(ServletContext.class); if(!configuration.getBooleanProperty(METRICS_NOOP_PROPERTY, true)) { final PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); final List<Tag> tagList = TagUtil.convertTags(ContextManagerImpl.getInstance().getGlobalContexts()); new ClassLoaderMetrics(tagList).bindTo(prometheusRegistry); new JvmMemoryMetrics(tagList).bindTo(prometheusRegistry); new JvmGcMetrics(tagList).bindTo(prometheusRegistry); new ProcessorMetrics(tagList).bindTo(prometheusRegistry); new JvmThreadMetrics(tagList).bindTo(prometheusRegistry); servletContext.addFilter(METRICS_SERVLET_FILTER_NAME, new RequestMetricsFilter()) .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ALL_URL_MAPPING); servletContext.addListener(new MetricsHttpSessionListener()); servletContext.addServlet(METRICS_SERVLET_NAME, new MetricsServlet(prometheusRegistry)) .addMapping(configuration.getProperty(METRICS_ENDPOINT_PROPERTY)); MetricsImpl.getInstance().init(prometheusRegistry); } } }
public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.setDisplayName(getDisplayName()); appContext.register(clz); appContext.setServletContext(servletContext); servletContext.addListener(new ContextLoaderListener(appContext)); Dynamic servlet = servletContext.addServlet(DISPATCHER, new DispatcherServlet(appContext)); servlet.addMapping("/"); servlet.setLoadOnStartup(1); FilterRegistration.Dynamic openSQLSessionInViewFilterChain = servletContext.addFilter(OPEN_SQL_SESSION_IN_VIEW_FILTER, OpenSQLSessionInViewFilter.class); openSQLSessionInViewFilterChain.addMappingForUrlPatterns(null, false, "/*");
public final void onStartup(final ServletContext servletContext) throws ServletException { final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); servletContext.addListener(new ContextLoaderListener(context)); propertySources(servletContext.getContextPath(), context); MutablePropertySources propertySources = propertyConfig.getLeft(); Set<String> namespace = Sets.newHashSet(namespace(context.getEnvironment())); ServletRegistration.Dynamic dispatcher = servletContext.addServlet( "spring-dispatcher", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping(dispatcherMapping());
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(servletContext); registerConfiguration(context); servletContext.addListener(new ContextLoaderListener(context)); context.refresh(); Environment env = context.getBean(Environment.class); Dynamic registration = servletContext.addServlet( ClassUtils.getShortNameAsProperty(SpringServlet.class), new SpringServlet(context)); String mapping = env .getProperty(RootMappedCondition.URL_MAPPING_PROPERTY, "/*"); Map<String, String> initParameters = new HashMap<>(); if (RootMappedCondition.isRootMapping(mapping)) { Dynamic dispatcherRegistration = servletContext .addServlet("dispatcher", new DispatcherServlet(context)); dispatcherRegistration.addMapping("/*"); mapping = VaadinServletConfiguration.VAADIN_SERVLET_MAPPING; initParameters.put(Constants.SERVLET_PARAMETER_PUSH_URL, mapping.replace("*", "")); } registration.setInitParameters(initParameters); registration.addMapping(mapping); registration.setAsyncSupported( Boolean.TRUE.toString().equals(env.getProperty( "vaadin.asyncSupported", Boolean.TRUE.toString()))); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); webApplicationContext.register(AppConfig.class); DispatcherServlet dispatcherServlet = new DispatcherServlet(webApplicationContext); ServletRegistration.Dynamic dynamic = servletContext.addServlet("dispatcherServlet", dispatcherServlet); dynamic.addMapping("/"); } }
public class MyWebApplicationInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext container) { ServletRegistration.Dynamic registration = container.addServlet("dispatcher", new DispatcherServlet()); registration.setLoadOnStartup(1); registration.addMapping("/example/*"); } }
@Override public void onStartup(ServletContext ctx) { if (ServletContainerInitializerUtil.avoidDoubleInit(this, ctx)) return; final AlertingPlugin alertingPlugin = Stagemonitor.getPlugin(AlertingPlugin.class); ctx.addServlet(AlerterTypeServlet.class.getSimpleName(), new AlerterTypeServlet(alertingPlugin, Stagemonitor.getMeasurementSession())) .addMapping("/stagemonitor/alerter-types"); ctx.addServlet(IncidentServlet.class.getSimpleName(), new IncidentServlet(alertingPlugin)) .addMapping("/stagemonitor/incidents"); ctx.addServlet(TestAlertSenderServlet.class.getSimpleName(), new TestAlertSenderServlet()) .addMapping("/stagemonitor/test-alert"); } }
AnnotationConfigWebApplicationContext rootWebContext = new AnnotationConfigWebApplicationContext(); rootWebContext.setId(ROOT_WEB_CONTEXT_ID); rootWebContext.setParent(MangoRuntimeContextConfiguration.getRuntimeContext()); rootWebContext.register(MangoRootWebContextConfiguration.class); context.addListener(new ContextLoaderListener(rootWebContext)); context.addServlet(JSP_DISPATCHER_NAME, new DispatcherServlet(jspDispatcherContext)); jspDispatcher.setLoadOnStartup(1); jspDispatcher.addMapping("*.htm", "*.shtm"); context.addServlet(ROOT_REST_DISPATCHER_NAME, new DispatcherServlet(rootRestContext)); rootRestDispatcher.setLoadOnStartup(2); rootRestDispatcher.addMapping("/rest/*"); rootRestDispatcher.addMapping( "/swagger/v2/api-docs", "/swagger-resources/configuration/ui",
public void onStartup(final ServletContext servletContext) { servletContext.setInitParameter("contextConfigLocation", "<NONE>"); AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); root.register(SpringWebConfig.class); root.setConfigLocation("com.jtbdevelopment"); servletContext.addListener(new ContextLoaderListener(root)); Dynamic jersey = servletContext.addServlet("REST", ServletContainer.class); jersey.setLoadOnStartup(0); Map<String, String> map = new HashMap<>(); map.put("jersey.config.server.provider.packages", "com.jtbdevelopment"); map.put("jersey.config.server.provider.classnames", "org.glassfish.jersey.filter.LoggingFilter;org.glassfish.jersey.message.DeflateEncoder;org.glassfish.jersey.message.GZipEncoder;org.glassfish.jersey.server.filter.EncodingFilter"); map.put("jersey.config.server.tracing", "ALL"); jersey.setInitParameters(map); jersey.addMapping("/api/*"); }