List of usage examples for org.springframework.context ApplicationContextException ApplicationContextException
public ApplicationContextException(String msg)
From source file:com.quartzdesk.executor.web.spring.SpringProfilesActivator.java
/** * Merges properties from the {@code default-quartzdesk-executor.properties} and * <code>${quartzdesk-executor.work.dir}/quartzdesk-executor.properties</code> (if it exists) and returns the value * of the {@code db.profile.name} configuration property. * * @param workDir the QuartzDesk Executor work directory. * @return the database profile to activate. *//* w ww . j a va 2 s . c om*/ private String getDatabaseProfile(WorkDir workDir) { Properties mergedCfg = new Properties(); /* * 1. read default-quartzdesk-executor.properties */ InputStream defaultCfgIns = null; try { defaultCfgIns = CommonUtils.getResourceAsStream(DEFAULT_QUARTZDESK_EXECUTOR_CFG); if (defaultCfgIns == null) throw new ApplicationContextException("Default QuartzDesk Executor configuration: " + DEFAULT_QUARTZDESK_EXECUTOR_CFG + " not found."); Properties defaultCfg = new Properties(); defaultCfg.load(defaultCfgIns); mergedCfg.putAll(defaultCfg); } catch (IOException e) { throw new ApplicationContextException( "Error reading default QuartzDesk Executor configuration: " + DEFAULT_QUARTZDESK_EXECUTOR_CFG, e); } finally { IOUtils.close(defaultCfgIns); } /* * 2. read ${quartzdesk-executor.work.dir}/quartzdesk-executor.properties */ File cfgFile = new File(workDir.getRoot(), "quartzdesk-executor.properties"); if (IOUtils.isReadableFile(cfgFile)) { InputStream cfgIns = null; try { cfgIns = new FileInputStream(cfgFile); Properties cfg = new Properties(); cfg.load(cfgIns); mergedCfg.putAll(cfg); } catch (IOException e) { throw new ApplicationContextException( "Error reading QuartzDesk configuration: " + cfgFile.getAbsoluteFile(), e); } finally { IOUtils.close(cfgIns); } } String dbProfile = mergedCfg.getProperty(CONFIG_KEY_DB_PROFILE); if (dbProfile == null) { throw new ApplicationContextException( "QuartzDesk Executor configuration property: " + CONFIG_KEY_DB_PROFILE + " not defined."); } return dbProfile.trim(); }
From source file:atunit.spring.SpringContainer.java
protected void loadBeanDefinitions(Class<?> testClass, BeanDefinitionRegistry registry) { XmlBeanDefinitionReader xml = new XmlBeanDefinitionReader(registry); String resourceName = testClass.getSimpleName() + ".xml"; Context ctxAnno = testClass.getAnnotation(Context.class); if (ctxAnno != null) { resourceName = ctxAnno.value();//from w w w . jav a 2s .c o m } URL xmlUrl = testClass.getResource(resourceName); if (xmlUrl != null) { xml.loadBeanDefinitions(new UrlResource(xmlUrl)); } else if (ctxAnno != null) { // is this the appropriate exception here? throw new ApplicationContextException("Could not find context file named " + resourceName); } }
From source file:org.jasig.cas.web.init.SafeDispatcherServlet.java
/** * @throws ApplicationContextException if the DispatcherServlet does not * initialize properly, but the servlet attempts to process a request. *//* ww w. j a v a2 s. c om*/ public void service(final ServletRequest req, final ServletResponse resp) throws ServletException, IOException { /* * Since our container calls only this method and not any of the other * HttpServlet runtime methods, such as doDelete(), etc., delegating * this method is sufficient to delegate all of the methods in the * HttpServlet API. */ if (this.initSuccess) { this.delegate.service(req, resp); } else { throw new ApplicationContextException("Unable to initialize application context."); } }
From source file:com.example.app.config.ProjectConfig.java
/** * Example to test if weaving is working. * * @param event the event./* w w w . java 2s . c om*/ */ @SuppressFBWarnings("DM_EXIT") @Override public void onApplicationEvent(ContextRefreshedEvent event) { if (!new AspectWeavingTest().isConfigured()) { ApplicationContext applicationContext = event.getApplicationContext(); try { if (applicationContext instanceof AbstractApplicationContext) ((AbstractApplicationContext) applicationContext).close(); } finally { ApplicationContextException ex = new ApplicationContextException( "AspectJ weaving is not working. Configure compile-time or load-time weaving."); _logger.fatal("AspectJ weaving misconfiguration.", ex); } System.exit(1); } }
From source file:com.example.app.config.MyAppConfig.java
/** * Example to test if weaving is working. * @param event the event./*from ww w. j a v a 2s . c o m*/ */ @SuppressFBWarnings("DM_EXIT") @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { if (!new AspectWeavingTest().isConfigured()) { ApplicationContextEvent ace = (ApplicationContextEvent) event; ApplicationContext applicationContext = ace.getApplicationContext(); try { if (applicationContext instanceof AbstractApplicationContext) ((AbstractApplicationContext) applicationContext).close(); } finally { ApplicationContextException ex = new ApplicationContextException( "AspectJ weaving is not working. Configure compile-time or load-time weaving."); _logger.fatal("AspectJ weaving misconfiguration.", ex); } System.exit(1); } } }
From source file:org.codehaus.groovy.grails.plugins.spring.ws.ReloadablePayloadRootQNameEndpointMapping.java
/** * Register the given endpoint instance under the registration key. * * @param key the string representation of the registration key * @param endpoint the endpoint instance * @throws org.springframework.beans.BeansException * if the endpoint could not be registered *//*w w w . j av a2s . c om*/ protected void registerEndpoint(String key, Object endpoint) throws BeansException { Object mappedEndpoint = endpointMap.get(key); if (mappedEndpoint != null) { throw new ApplicationContextException("Cannot map endpoint [" + endpoint + "] on registration key [" + key + "]: there's already endpoint [" + mappedEndpoint + "] mapped"); } if (!lazyInitEndpoints && endpoint instanceof String) { String endpointName = (String) endpoint; endpoint = resolveStringEndpoint(endpointName); } if (endpoint == null) { throw new ApplicationContextException("Could not find endpoint for key [" + key + "]"); } endpointMap.put(key, endpoint); if (logger.isDebugEnabled()) { logger.debug("Mapped key [" + key + "] onto endpoint [" + endpoint + "]"); } }
From source file:org.solmix.runtime.support.spring.ContainerApplicationContext.java
@Override protected Resource[] getConfigResources() { List<Resource> resources = new ArrayList<Resource>(); if (includeDefault) { try {/*from ww w .j ava 2s .c o m*/ PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver( Thread.currentThread().getContextClassLoader()); Collections.addAll(resources, resolver.getResources(DEFAULT_CFG_FILE)); Resource[] exts = resolver.getResources(DEFAULT_EXT_CFG_FILE); for (Resource r : exts) { InputStream is = r.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = rd.readLine(); while (line != null) { if (!"".equals(line)) { resources.add(resolver.getResource(line)); } line = rd.readLine(); } is.close(); } } catch (IOException ex) { // ignore } } boolean usingDefault = false; if (cfgFiles == null) { String userConfig = System.getProperty(BeanConfigurer.USER_CFG_FILE_PROPERTY_NAME); if (userConfig != null) { cfgFiles = new String[] { userConfig }; } } if (cfgFiles == null) { usingDefault = true; cfgFiles = new String[] { BeanConfigurer.USER_CFG_FILE }; } for (String cfgFile : cfgFiles) { final Resource f = findResource(cfgFile); if (f != null && f.exists()) { resources.add(f); LOG.info("Used configed file {}", cfgFile); } else { if (!usingDefault) { LOG.warn("Can't find configure file {}", cfgFile); throw new ApplicationContextException("Can't find configure file"); } } } if (cfgURLs != null) { for (URL u : cfgURLs) { UrlResource ur = new UrlResource(u); if (ur.exists()) { resources.add(ur); } else { LOG.warn("Can't find configure file {}", u.getPath()); } } } if (LOG.isDebugEnabled()) { LOG.debug("Creating application context with resources " + resources.size()); } if (0 == resources.size()) { return null; } Resource[] res = new Resource[resources.size()]; res = resources.toArray(res); return res; }
From source file:org.codehaus.groovy.grails.plugins.spring.ws.ReloadablePayloadRootQNameEndpointMapping.java
/** * Registers annd checks the set endpoints. Checks the beans set through <code>setEndpointMap</code> and * <code>setMappings</code>, and registers the bean names found in the application context, if * <code>registerBeanNames</code> is set to <code>true</code>. * * @throws ApplicationContextException if either of the endpoints defined via <code>setEndpointMap</code> or * <code>setMappings</code> is invalid * @see #setEndpointMap(java.util.Map)/*ww w.j ava 2s.c om*/ * @see #setMappings(java.util.Properties) * @see #setRegisterBeanNames(boolean) */ protected final void initApplicationContext() throws BeansException { for (Map.Entry<String, Object> entry : temporaryEndpointMap.entrySet()) { String key = entry.getKey(); Object endpoint = entry.getValue(); if (!validateLookupKey(key)) { throw new ApplicationContextException("Invalid key [" + key + "] for endpoint [" + endpoint + "]"); } registerEndpoint(key, endpoint); } temporaryEndpointMap = null; if (registerBeanNames) { if (logger.isDebugEnabled()) { logger.debug( "Looking for endpoint mappings in application context: [" + getApplicationContext() + "]"); } String[] beanNames = getApplicationContext().getBeanDefinitionNames(); for (int i = 0; i < beanNames.length; i++) { if (validateLookupKey(beanNames[i])) { registerEndpoint(beanNames[i], beanNames[i]); } String[] aliases = getApplicationContext().getAliases(beanNames[i]); for (int j = 0; j < aliases.length; j++) { if (validateLookupKey(aliases[j])) { registerEndpoint(aliases[j], beanNames[i]); } } } } }
From source file:org.codehaus.groovy.grails.plugins.spring.ws.ReloadablePayloadRootQNameEndpointMapping.java
public void registerEndpoints(Map<String, Object> endpointsMap) throws BeansException { endpointMap.clear();/*w ww. j av a2s . co m*/ for (Map.Entry<String, Object> entry : endpointsMap.entrySet()) { String key = entry.getKey(); Object endpoint = entry.getValue(); if (!validateLookupKey(key)) { throw new ApplicationContextException("Invalid key [" + key + "] for endpoint [" + endpoint + "]"); } registerEndpoint(key, endpoint); } }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoader.java
/** * Instantiate the root PortletApplicationContext for this loader, either the * default context class or a custom context class if specified. * <p>This implementation expects custom contexts to implement the * {@link ConfigurablePortletApplicationContext} interface. * Can be overridden in subclasses.//from w ww . j a va2 s .c o m * <p>In addition, {@link #customizeContext} gets called prior to refreshing the * context, allowing subclasses to perform custom modifications to the context. * @param sc current portlet context * @return the root WebApplicationContext * @see ConfigurablePortletApplicationContext */ protected PortletApplicationContext createPortletApplicationContext(PortletContext sc) { Class<?> contextClass = determineContextClass(sc); if (!PortletApplicationContext.class.isAssignableFrom(contextClass)) { throw new ApplicationContextException("Custom context class [" + contextClass.getName() + "] is not of type [" + PortletApplicationContext.class.getName() + "]"); } PortletApplicationContext wac = (PortletApplicationContext) BeanUtils.instantiateClass(contextClass); return wac; }