List of usage examples for org.springframework.context ApplicationContextException ApplicationContextException
public ApplicationContextException(String msg, Throwable cause)
From source file:org.springframework.context.support.DefaultLifecycleProcessor.java
/** * Start the specified bean as part of the given set of Lifecycle beans, * making sure that any beans that it depends on are started first. * @param lifecycleBeans Map with bean name as key and Lifecycle instance as value * @param beanName the name of the bean to start *///from w ww .j ava2s. c o m private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String beanName, boolean autoStartupOnly) { Lifecycle bean = lifecycleBeans.remove(beanName); if (bean != null && !this.equals(bean)) { String[] dependenciesForBean = getBeanFactory().getDependenciesForBean(beanName); for (String dependency : dependenciesForBean) { doStart(lifecycleBeans, dependency, autoStartupOnly); } if (!bean.isRunning() && (!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) { if (logger.isDebugEnabled()) { logger.debug("Starting bean '" + beanName + "' of type [" + bean.getClass() + "]"); } try { bean.start(); } catch (Throwable ex) { throw new ApplicationContextException("Failed to start bean '" + beanName + "'", ex); } if (logger.isDebugEnabled()) { logger.debug("Successfully started bean '" + beanName + "'"); } } } }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer.java
/** * Initializes a Spring ApplicationContext with the given parameters specified with a GemFire <initializer> * block in cache.xml.//from w ww . j a v a 2 s . co m * * @param parameters a Properties object containing the configuration parameters and settings defined in the * GemFire cache.xml <initializer> block for the declared SpringContextBootstrappingInitializer * GemFire Declarable object. * @throws org.springframework.context.ApplicationContextException if the Spring ApplicationContext could not be * successfully created, configured and initialized. * @see #createApplicationContext(String[], String[]) * @see #initApplicationContext(org.springframework.context.ConfigurableApplicationContext) * @see #refreshApplicationContext(org.springframework.context.ConfigurableApplicationContext) * @see java.util.Properties */ @Override public void init(final Properties parameters) { try { synchronized (SpringContextBootstrappingInitializer.class) { if (applicationContext == null || !applicationContext.isActive()) { String basePackages = parameters.getProperty(BASE_PACKAGES_PARAMETER); String contextConfigLocations = parameters.getProperty(CONTEXT_CONFIG_LOCATIONS_PARAMETER); String[] basePackagesArray = StringUtils.delimitedListToStringArray( StringUtils.trimWhitespace(basePackages), COMMA_DELIMITER, CHARS_TO_DELETE); String[] contextConfigLocationsArray = StringUtils.delimitedListToStringArray( StringUtils.trimWhitespace(contextConfigLocations), COMMA_DELIMITER, CHARS_TO_DELETE); ConfigurableApplicationContext localApplicationContext = refreshApplicationContext( initApplicationContext( createApplicationContext(basePackagesArray, contextConfigLocationsArray))); Assert.state(localApplicationContext.isRunning(), String.format( "The Spring ApplicationContext (%1$s) failed to be properly initialized with the context config files (%2$s) or base packages (%3$s)!", nullSafeGetApplicationContextId(localApplicationContext), Arrays.toString(contextConfigLocationsArray), Arrays.toString(basePackagesArray))); applicationContext = localApplicationContext; } } } catch (Throwable cause) { String message = "Failed to bootstrap the Spring ApplicationContext!"; logger.error(message, cause); throw new ApplicationContextException(message, cause); } }
From source file:org.springframework.web.context.ContextLoader.java
/** * Return the WebApplicationContext implementation class to use, either the * default XmlWebApplicationContext or a custom context class if specified. * @param servletContext current servlet context * @return the WebApplicationContext implementation class to use * @see #CONTEXT_CLASS_PARAM/* ww w.j a v a 2 s. c om*/ * @see org.springframework.web.context.support.XmlWebApplicationContext */ protected Class<?> determineContextClass(ServletContext servletContext) { String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM); if (contextClassName != null) { try { return ClassUtils.forName(contextClassName, ClassUtils.getDefaultClassLoader()); } catch (ClassNotFoundException ex) { throw new ApplicationContextException( "Failed to load custom context class [" + contextClassName + "]", ex); } } else { contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName()); try { return ClassUtils.forName(contextClassName, ContextLoader.class.getClassLoader()); } catch (ClassNotFoundException ex) { throw new ApplicationContextException( "Failed to load default context class [" + contextClassName + "]", ex); } } }
From source file:org.theospi.portfolio.shared.control.XmlElementView.java
/** * Invoked on startup. Looks for a single VelocityConfig bean to * find the relevant VelocityEngine for this factory. *///w w w . ja v a 2 s .co m protected void initApplicationContext() throws BeansException { super.initApplicationContext(); if (this.velocityEngine == null) { try { VelocityEngineFactory velocityConfig = (VelocityEngineFactory) BeanFactoryUtils .beanOfTypeIncludingAncestors(getApplicationContext(), VelocityEngineFactory.class, true, true); this.velocityEngine = velocityConfig.getVelocityEngine(); } catch (NoSuchBeanDefinitionException ex) { throw new ApplicationContextException( "Must define a single VelocityConfig bean in this web application " + "context (may be inherited): VelocityConfigurer is the usual implementation. " + "This bean may be given any name.", ex); } } try { // check that we can get the template, even if we might subsequently get it again this.template = getVelocityTemplate(); } catch (ResourceNotFoundException ex) { throw new ApplicationContextException("Cannot find Velocity template for URL [" + getBaseUrl() + "]: Did you specify the correct resource loader path?", ex); } catch (Exception ex) { throw new ApplicationContextException("Cannot load Velocity template for URL [" + getBaseUrl() + "]", ex); } }