/** * Create a new {@link XmlServletWebServerApplicationContext}, loading bean * definitions from the given resources and automatically refreshing the context. * @param resources the resources to load from */ public XmlServletWebServerApplicationContext(Resource... resources) { load(resources); refresh(); }
/** * Create a new {@link AnnotationConfigServletWebServerApplicationContext}, scanning * for bean definitions in the given packages and automatically refreshing the * context. * @param basePackages the packages to check for annotated classes */ public AnnotationConfigServletWebServerApplicationContext(String... basePackages) { this(); scan(basePackages); refresh(); }
/** * Create a new {@link AnnotationConfigServletWebServerApplicationContext}, deriving * bean definitions from the given annotated classes and automatically refreshing the * context. * @param annotatedClasses one or more annotated classes, e.g. {@code @Configuration} * classes */ public AnnotationConfigServletWebServerApplicationContext( Class<?>... annotatedClasses) { this(); register(annotatedClasses); refresh(); }
@Override public void onApplicationEvent(ServletWebServerInitializedEvent event) { this.port = event.getSource().getPort(); }
private void registerWebApplicationScopes() { ExistingWebApplicationScopes existingScopes = new ExistingWebApplicationScopes( getBeanFactory()); WebApplicationContextUtils.registerWebApplicationScopes(getBeanFactory()); existingScopes.restore(); }
@Override protected void finishRefresh() { super.finishRefresh(); WebServer webServer = startWebServer(); if (webServer != null) { publishEvent(new ServletWebServerInitializedEvent(webServer, this)); } }
/** * {@inheritDoc} * <p> * Delegates the given environment to underlying {@link XmlBeanDefinitionReader}. * Should be called before any call to {@link #load}. */ @Override public void setEnvironment(ConfigurableEnvironment environment) { super.setEnvironment(environment); this.reader.setEnvironment(this.getEnvironment()); }
/** * Register ServletContextAwareProcessor. * @see ServletContextAwareProcessor */ @Override protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.addBeanPostProcessor( new WebApplicationContextServletContextAwareProcessor(this)); beanFactory.ignoreDependencyInterface(ServletContextAware.class); registerWebApplicationScopes(); }
@Override protected Resource getResourceByPath(String path) { if (getServletContext() == null) { return new ClassPathContextResource(path, getClassLoader()); } return new ServletContextResource(getServletContext(), path); }
@Override protected void onClose() { super.onClose(); stopAndReleaseWebServer(); }
/** * Create a new {@link XmlServletWebServerApplicationContext} that needs to be * {@linkplain #load loaded} and then manually {@link #refresh refreshed}. */ public XmlServletWebServerApplicationContext() { this.reader.setEnvironment(this.getEnvironment()); }
/** * Returns {@link ServletContextInitializer}s that should be used with the embedded * web server. By default this method will first attempt to find * {@link ServletContextInitializer}, {@link Servlet}, {@link Filter} and certain * {@link EventListener} beans. * @return the servlet initializer beans */ protected Collection<ServletContextInitializer> getServletContextInitializerBeans() { return new ServletContextInitializerBeans(getBeanFactory()); }
@Override protected void prepareRefresh() { this.scanner.clearCache(); super.prepareRefresh(); }
@Override protected void onRefresh() { super.onRefresh(); try { createWebServer(); } catch (Throwable ex) { throw new ApplicationContextException("Unable to start web server", ex); } }
@Override public void onApplicationEvent(ServletWebServerInitializedEvent event) { this.port = event.getSource().getPort(); }
/** * Create a new {@link XmlServletWebServerApplicationContext}, loading bean * definitions from the given resource locations and automatically refreshing the * context. * @param resourceLocations the resources to load from */ public XmlServletWebServerApplicationContext(String... resourceLocations) { load(resourceLocations); refresh(); }
@Override public final void refresh() throws BeansException, IllegalStateException { try { super.refresh(); } catch (RuntimeException ex) { stopAndReleaseWebServer(); throw ex; } }
@Override public void onApplicationEvent(ServletWebServerInitializedEvent event) { this.port = event.getSource().getPort(); }
/** * Create a new {@link XmlServletWebServerApplicationContext}, loading bean * definitions from the given resource locations and automatically refreshing the * context. * @param relativeClass class whose package will be used as a prefix when loading each * specified resource name * @param resourceNames relatively-qualified names of resources to load */ public XmlServletWebServerApplicationContext(Class<?> relativeClass, String... resourceNames) { load(relativeClass, resourceNames); refresh(); }
@Override public void onApplicationEvent(ServletWebServerInitializedEvent event) { this.port = event.getSource().getPort(); }