Java Code Examples for org.springframework.context.ConfigurableApplicationContext#isActive()

The following examples show how to use org.springframework.context.ConfigurableApplicationContext#isActive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DelegatingFilterProxy.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Return the {@code WebApplicationContext} passed in at construction time, if available.
 * Otherwise, attempt to retrieve a {@code WebApplicationContext} from the
 * {@code ServletContext} attribute with the {@linkplain #setContextAttribute
 * configured name} if set. Otherwise look up a {@code WebApplicationContext} under
 * the well-known "root" application context attribute. The
 * {@code WebApplicationContext} must have already been loaded and stored in the
 * {@code ServletContext} before this filter gets initialized (or invoked).
 * <p>Subclasses may override this method to provide a different
 * {@code WebApplicationContext} retrieval strategy.
 * @return the {@code WebApplicationContext} for this proxy, or {@code null} if not found
 * @see #DelegatingFilterProxy(String, WebApplicationContext)
 * @see #getContextAttribute()
 * @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)
 * @see WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
 */
@Nullable
protected WebApplicationContext findWebApplicationContext() {
	if (this.webApplicationContext != null) {
		// The user has injected a context at construction time -> use it...
		if (this.webApplicationContext instanceof ConfigurableApplicationContext) {
			ConfigurableApplicationContext cac = (ConfigurableApplicationContext) this.webApplicationContext;
			if (!cac.isActive()) {
				// The context has not yet been refreshed -> do so before returning it...
				cac.refresh();
			}
		}
		return this.webApplicationContext;
	}
	String attrName = getContextAttribute();
	if (attrName != null) {
		return WebApplicationContextUtils.getWebApplicationContext(getServletContext(), attrName);
	}
	else {
		return WebApplicationContextUtils.findWebApplicationContext(getServletContext());
	}
}
 
Example 2
Source File: DelegatingFilterProxy.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Return the {@code WebApplicationContext} passed in at construction time, if available.
 * Otherwise, attempt to retrieve a {@code WebApplicationContext} from the
 * {@code ServletContext} attribute with the {@linkplain #setContextAttribute
 * configured name} if set. Otherwise look up a {@code WebApplicationContext} under
 * the well-known "root" application context attribute. The
 * {@code WebApplicationContext} must have already been loaded and stored in the
 * {@code ServletContext} before this filter gets initialized (or invoked).
 * <p>Subclasses may override this method to provide a different
 * {@code WebApplicationContext} retrieval strategy.
 * @return the {@code WebApplicationContext} for this proxy, or {@code null} if not found
 * @see #DelegatingFilterProxy(String, WebApplicationContext)
 * @see #getContextAttribute()
 * @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)
 * @see WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
 */
@Nullable
protected WebApplicationContext findWebApplicationContext() {
	if (this.webApplicationContext != null) {
		// The user has injected a context at construction time -> use it...
		if (this.webApplicationContext instanceof ConfigurableApplicationContext) {
			ConfigurableApplicationContext cac = (ConfigurableApplicationContext) this.webApplicationContext;
			if (!cac.isActive()) {
				// The context has not yet been refreshed -> do so before returning it...
				cac.refresh();
			}
		}
		return this.webApplicationContext;
	}
	String attrName = getContextAttribute();
	if (attrName != null) {
		return WebApplicationContextUtils.getWebApplicationContext(getServletContext(), attrName);
	}
	else {
		return WebApplicationContextUtils.findWebApplicationContext(getServletContext());
	}
}
 
Example 3
Source File: EventNetstrapSpringRunListener.java    From netstrap with Apache License 2.0 6 votes vote down vote up
@Override
public void failed(ConfigurableApplicationContext context, Throwable exception) {
    FailedApplicationEvent event = new FailedApplicationEvent(this.application, context, exception);
    if (context != null && context.isActive()) {
        context.publishEvent(event);
    } else {
        if (context instanceof AbstractApplicationContext) {
            for (ApplicationListener<?> listener : ((AbstractApplicationContext) context)
                    .getApplicationListeners()) {
                this.initialMulticaster.addApplicationListener(listener);
            }
        }

        this.initialMulticaster.setErrorHandler(new LoggingErrorHandler());
        this.initialMulticaster.multicastEvent(event);
    }
}
 
Example 4
Source File: DelegatingFilterProxy.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the {@code WebApplicationContext} passed in at construction time, if available.
 * Otherwise, attempt to retrieve a {@code WebApplicationContext} from the
 * {@code ServletContext} attribute with the {@linkplain #setContextAttribute
 * configured name} if set. Otherwise look up a {@code WebApplicationContext} under
 * the well-known "root" application context attribute. The
 * {@code WebApplicationContext} must have already been loaded and stored in the
 * {@code ServletContext} before this filter gets initialized (or invoked).
 * <p>Subclasses may override this method to provide a different
 * {@code WebApplicationContext} retrieval strategy.
 * @return the {@code WebApplicationContext} for this proxy, or {@code null} if not found
 * @see #DelegatingFilterProxy(String, WebApplicationContext)
 * @see #getContextAttribute()
 * @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)
 * @see WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
 */
protected WebApplicationContext findWebApplicationContext() {
	if (this.webApplicationContext != null) {
		// The user has injected a context at construction time -> use it...
		if (this.webApplicationContext instanceof ConfigurableApplicationContext) {
			ConfigurableApplicationContext cac = (ConfigurableApplicationContext) this.webApplicationContext;
			if (!cac.isActive()) {
				// The context has not yet been refreshed -> do so before returning it...
				cac.refresh();
			}
		}
		return this.webApplicationContext;
	}
	String attrName = getContextAttribute();
	if (attrName != null) {
		return WebApplicationContextUtils.getWebApplicationContext(getServletContext(), attrName);
	}
	else {
		return WebApplicationContextUtils.findWebApplicationContext(getServletContext());
	}
}
 
Example 5
Source File: DelegatingFilterProxy.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Return the {@code WebApplicationContext} passed in at construction time, if available.
 * Otherwise, attempt to retrieve a {@code WebApplicationContext} from the
 * {@code ServletContext} attribute with the {@linkplain #setContextAttribute
 * configured name} if set. Otherwise look up a {@code WebApplicationContext} under
 * the well-known "root" application context attribute. The
 * {@code WebApplicationContext} must have already been loaded and stored in the
 * {@code ServletContext} before this filter gets initialized (or invoked).
 * <p>Subclasses may override this method to provide a different
 * {@code WebApplicationContext} retrieval strategy.
 * @return the {@code WebApplicationContext} for this proxy, or {@code null} if not found
 * @see #DelegatingFilterProxy(String, WebApplicationContext)
 * @see #getContextAttribute()
 * @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)
 * @see WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
 */
protected WebApplicationContext findWebApplicationContext() {
	if (this.webApplicationContext != null) {
		// The user has injected a context at construction time -> use it...
		if (this.webApplicationContext instanceof ConfigurableApplicationContext) {
			ConfigurableApplicationContext cac = (ConfigurableApplicationContext) this.webApplicationContext;
			if (!cac.isActive()) {
				// The context has not yet been refreshed -> do so before returning it...
				cac.refresh();
			}
		}
		return this.webApplicationContext;
	}
	String attrName = getContextAttribute();
	if (attrName != null) {
		return WebApplicationContextUtils.getWebApplicationContext(getServletContext(), attrName);
	}
	else {
		return WebApplicationContextUtils.findWebApplicationContext(getServletContext());
	}
}
 
Example 6
Source File: AbstractReactiveWebInitializer.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Refresh the given application context, if necessary.
 */
protected void refreshApplicationContext(ApplicationContext context) {
	if (context instanceof ConfigurableApplicationContext) {
		ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
		if (!cac.isActive()) {
			cac.refresh();
		}
	}
}
 
Example 7
Source File: AbstractReactiveWebInitializer.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Refresh the given application context, if necessary.
 */
protected void refreshApplicationContext(ApplicationContext context) {
	if (context instanceof ConfigurableApplicationContext) {
		ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
		if (!cac.isActive()) {
			cac.refresh();
		}
	}
}
 
Example 8
Source File: SpringApplication.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private int getExitCodeFromMappedException(ConfigurableApplicationContext context,
		Throwable exception) {
	if (context == null || !context.isActive()) {
		return 0;
	}
	ExitCodeGenerators generators = new ExitCodeGenerators();
	Collection<ExitCodeExceptionMapper> beans = context
			.getBeansOfType(ExitCodeExceptionMapper.class).values();
	generators.addAll(exception, beans);
	return generators.getExitCode();
}
 
Example 9
Source File: Springs.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public boolean isActive(){
	if(appContext instanceof ConfigurableApplicationContext){
		ConfigurableApplicationContext cac = (ConfigurableApplicationContext) appContext;
		return cac.isActive();
	}
	return isInitialized();
}