当前位置: 首页>>代码示例>>Java>>正文


Java ApplicationContextException类代码示例

本文整理汇总了Java中org.springframework.context.ApplicationContextException的典型用法代码示例。如果您正苦于以下问题:Java ApplicationContextException类的具体用法?Java ApplicationContextException怎么用?Java ApplicationContextException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ApplicationContextException类属于org.springframework.context包,在下文中一共展示了ApplicationContextException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: autodetectViewConfig

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
protected ScriptTemplateConfig autodetectViewConfig() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				getApplicationContext(), ScriptTemplateConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException("Expected a single ScriptTemplateConfig bean in the current " +
				"Servlet web application context or the parent root context: ScriptTemplateConfigurer is " +
				"the usual implementation. This bean may have any name.", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:ScriptTemplateView.java

示例2: initApplicationContext

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
/**
 * Checks to see that a valid report file URL is supplied in the
 * configuration. Compiles the report file is necessary.
 * <p>Subclasses can add custom initialization logic by overriding
 * the {@link #onInit} method.
 */
@Override
protected final void initApplicationContext() throws ApplicationContextException {
	this.report = loadReport();

	// Load sub reports if required, and check data source parameters.
	if (this.subReportUrls != null) {
		if (this.subReportDataKeys != null && this.subReportDataKeys.length > 0 && this.reportDataKey == null) {
			throw new ApplicationContextException(
					"'reportDataKey' for main report is required when specifying a value for 'subReportDataKeys'");
		}
		this.subReports = new HashMap<String, JasperReport>(this.subReportUrls.size());
		for (Enumeration<?> urls = this.subReportUrls.propertyNames(); urls.hasMoreElements();) {
			String key = (String) urls.nextElement();
			String path = this.subReportUrls.getProperty(key);
			Resource resource = getApplicationContext().getResource(path);
			this.subReports.put(key, loadReport(resource));
		}
	}

	// Convert user-supplied exporterParameters.
	convertExporterParameters();

	if (this.headers == null) {
		this.headers = new Properties();
	}
	if (!this.headers.containsKey(HEADER_CONTENT_DISPOSITION)) {
		this.headers.setProperty(HEADER_CONTENT_DISPOSITION, CONTENT_DISPOSITION_INLINE);
	}

	onInit();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:AbstractJasperReportsView.java

示例3: service

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @throws ApplicationContextException if the DispatcherServlet does not
 * initialize properly, but the servlet attempts to process a request.
 */
@Override
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.");
    }
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:21,代码来源:SafeDispatcherServlet.java

示例4: testService

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
@Test
public void testService() throws ServletException, IOException {
    this.safeServlet.init(this.mockConfig);

    ServletRequest mockRequest = new MockHttpServletRequest();
    ServletResponse mockResponse = new MockHttpServletResponse();

    try {
        this.safeServlet.service(mockRequest, mockResponse);
    } catch (final ApplicationContextException ace) {
        // good, threw the exception we expected.
        return;
    }

    fail("Should have thrown ApplicationContextException since init() failed.");
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:17,代码来源:SafeDispatcherServletTests.java

示例5: enforceExporterImporterDependency

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
/**
 * Takes care of enforcing the relationship between exporter and importers.
 * 
 * @param beanFactory
 */
private void enforceExporterImporterDependency(ConfigurableListableBeanFactory beanFactory) {
	Object instance = null;

	instance = AccessController.doPrivileged(new PrivilegedAction<Object>() {

		public Object run() {
			// create the service manager
			ClassLoader loader = AbstractOsgiBundleApplicationContext.class.getClassLoader();
			try {
				Class<?> managerClass = loader.loadClass(EXPORTER_IMPORTER_DEPENDENCY_MANAGER);
				return BeanUtils.instantiateClass(managerClass);
			} catch (ClassNotFoundException cnfe) {
				throw new ApplicationContextException("Cannot load class " + EXPORTER_IMPORTER_DEPENDENCY_MANAGER,
						cnfe);
			}
		}
	});

	// sanity check
	Assert.isInstanceOf(BeanFactoryAware.class, instance);
	Assert.isInstanceOf(BeanPostProcessor.class, instance);
	((BeanFactoryAware) instance).setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor((BeanPostProcessor) instance);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:30,代码来源:AbstractOsgiBundleApplicationContext.java

示例6: registerApplicationContext

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
static void registerApplicationContext(ConfigurableApplicationContext applicationContext) {
	String mbeanDomain = applicationContext.getEnvironment().getProperty(MBEAN_DOMAIN_PROPERTY_NAME);
	if (mbeanDomain != null) {
		synchronized (applicationContexts) {
			if (applicationContexts.isEmpty()) {
				try {
					MBeanServer server = ManagementFactory.getPlatformMBeanServer();
					server.registerMBean(new LiveBeansView(),
							new ObjectName(mbeanDomain, MBEAN_APPLICATION_KEY, applicationContext.getApplicationName()));
				}
				catch (Exception ex) {
					throw new ApplicationContextException("Failed to register LiveBeansView MBean", ex);
				}
			}
			applicationContexts.add(applicationContext);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:LiveBeansView.java

示例7: doStart

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
/**
 * 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
 */
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 = this.beanFactory.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 + "'");
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:DefaultLifecycleProcessor.java

示例8: refreshBeanFactory

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
/**
 * This implementation performs an actual refresh of this context's underlying
 * bean factory, shutting down the previous bean factory (if any) and
 * initializing a fresh bean factory for the next phase of the context's lifecycle.
 */
@Override
protected final void refreshBeanFactory() throws BeansException {
	if (hasBeanFactory()) {
		destroyBeans();
		closeBeanFactory();
	}
	try {
		DefaultListableBeanFactory beanFactory = createBeanFactory();
		beanFactory.setSerializationId(getId());
		customizeBeanFactory(beanFactory);
		loadBeanDefinitions(beanFactory);
		synchronized (this.beanFactoryMonitor) {
			this.beanFactory = beanFactory;
		}
	}
	catch (IOException ex) {
		throw new ApplicationContextException("I/O error parsing bean definition source for " + getDisplayName(), ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:AbstractRefreshableApplicationContext.java

示例9: setApplicationContext

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
@Override
public final void setApplicationContext(ApplicationContext context) throws BeansException {
	if (context == null && !isContextRequired()) {
		// Reset internal context state.
		this.applicationContext = null;
		this.messageSourceAccessor = null;
	}
	else if (this.applicationContext == null) {
		// Initialize with passed-in context.
		if (!requiredContextClass().isInstance(context)) {
			throw new ApplicationContextException(
					"Invalid application context: needs to be of type [" + requiredContextClass().getName() + "]");
		}
		this.applicationContext = context;
		this.messageSourceAccessor = new MessageSourceAccessor(context);
		initApplicationContext(context);
	}
	else {
		// Ignore reinitialization if same context passed in.
		if (this.applicationContext != context) {
			throw new ApplicationContextException(
					"Cannot reinitialize with different application context: current one is [" +
					this.applicationContext + "], passed-in one is [" + context + "]");
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:ApplicationObjectSupport.java

示例10: dataSource

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
@Bean(destroyMethod = "shutdown")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource() {
	log.debug("Configuring Datasource");
	if (dataSourcePropertyResolver.getProperty("url") == null
			&& dataSourcePropertyResolver.getProperty("databaseName") == null) {
		log.error(
				"Your database connection pool configuration is incorrect! The application"
						+ " cannot start. Please check your Spring profile, current profiles are: {}",
				Arrays.toString(env.getActiveProfiles()));

		throw new ApplicationContextException("Database connection pool is not configured correctly");
	}
	HikariConfig config = new HikariConfig();
	config.setDataSourceClassName(dataSourcePropertyResolver.getProperty("dataSourceClassName"));
	if (StringUtils.isEmpty(dataSourcePropertyResolver.getProperty("url"))) {
		config.addDataSourceProperty("databaseName", dataSourcePropertyResolver.getProperty("databaseName"));
		config.addDataSourceProperty("serverName", dataSourcePropertyResolver.getProperty("serverName"));
	} else {
		config.addDataSourceProperty("url", dataSourcePropertyResolver.getProperty("url"));
	}
	config.addDataSourceProperty("user", dataSourcePropertyResolver.getProperty("username"));
	config.addDataSourceProperty("password", dataSourcePropertyResolver.getProperty("password"));

	if (metricRegistry != null) {
		config.setMetricRegistry(metricRegistry);
	}
	return new HikariDataSource(config);
}
 
开发者ID:VHAINNOVATIONS,项目名称:BCDS,代码行数:30,代码来源:DatabaseConfiguration.java

示例11: refreshBeanFactory

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
/**��ʵ��ִ�д������ĵĵײ�bean factory��ʵ��ˢ�¡�
 * �ر���ǰ��bean����������еĻ����ͳ�ʼ���������ĵ��������ڵ���һ�׶ε�����bean����
 * <p>
 * This implementation performs an actual refresh of this context's underlying
 * bean factory, shutting down the previous bean factory (if any) and
 * initializing a fresh bean factory for the next phase of the context's lifecycle.
 */
@Override
protected final void refreshBeanFactory() throws BeansException {
	if (hasBeanFactory()) {
		destroyBeans();
		closeBeanFactory();
	}
	try {
		DefaultListableBeanFactory beanFactory = createBeanFactory();
		beanFactory.setSerializationId(getId());
		customizeBeanFactory(beanFactory);
		loadBeanDefinitions(beanFactory);
		synchronized (this.beanFactoryMonitor) {
			this.beanFactory = beanFactory;
		}
	}
	catch (IOException ex) {
		throw new ApplicationContextException("I/O error parsing bean definition source for " + getDisplayName(), ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:AbstractRefreshableApplicationContext.java

示例12: loadTemplates

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
/**
 * Load the {@link Templates} instance for the stylesheet at the configured location.
 */
private Templates loadTemplates() throws ApplicationContextException {
	Source stylesheetSource = getStylesheetSource();
	try {
		Templates templates = this.transformerFactory.newTemplates(stylesheetSource);
		if (logger.isDebugEnabled()) {
			logger.debug("Loading templates '" + templates + "'");
		}
		return templates;
	}
	catch (TransformerConfigurationException ex) {
		throw new ApplicationContextException("Can't load stylesheet from '" + getUrl() + "'", ex);
	}
	finally {
		closeSourceIfNecessary(stylesheetSource);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:XsltView.java

示例13: createWebApplicationContext

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
/**
 * Instantiate the WebApplicationContext for this servlet, either a default
 * {@link org.springframework.web.context.support.XmlWebApplicationContext}
 * or a {@link #setContextClass custom context class}, if set.
 * <p>This implementation expects custom contexts to implement the
 * {@link org.springframework.web.context.ConfigurableWebApplicationContext}
 * interface. Can be overridden in subclasses.
 * <p>Do not forget to register this servlet instance as application listener on the
 * created context (for triggering its {@link #onRefresh callback}, and to call
 * {@link org.springframework.context.ConfigurableApplicationContext#refresh()}
 * before returning the context instance.
 * @param parent the parent ApplicationContext to use, or {@code null} if none
 * @return the WebApplicationContext for this servlet
 * @see org.springframework.web.context.support.XmlWebApplicationContext
 */
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
	Class<?> contextClass = getContextClass();
	if (this.logger.isDebugEnabled()) {
		this.logger.debug("Servlet with name '" + getServletName() +
				"' will try to create custom WebApplicationContext context of class '" +
				contextClass.getName() + "'" + ", using parent context [" + parent + "]");
	}
	if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
		throw new ApplicationContextException(
				"Fatal initialization error in servlet with name '" + getServletName() +
				"': custom WebApplicationContext class [" + contextClass.getName() +
				"] is not of type ConfigurableWebApplicationContext");
	}
	ConfigurableWebApplicationContext wac =
			(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);

	wac.setEnvironment(getEnvironment());
	wac.setParent(parent);
	wac.setConfigLocation(getContextConfigLocation());

	configureAndRefreshWebApplicationContext(wac);

	return wac;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:FrameworkServlet.java

示例14: withNonExistentSubReport

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
@Test
public void withNonExistentSubReport() throws Exception {
	assumeTrue(canCompileReport);

	Map<String, Object> model = getModel();
	model.put("SubReportData", getProductData());

	Properties subReports = new Properties();
	subReports.put("ProductsSubReport", "org/springframework/ui/jasperreports/subReportChildFalse.jrxml");

	AbstractJasperReportsView view = getView(SUB_REPORT_PARENT);
	view.setReportDataKey("dataSource");
	view.setSubReportUrls(subReports);
	view.setSubReportDataKeys(new String[]{"SubReportData"});

	// Invalid report URL should throw ApplicationContextException
	exception.expect(ApplicationContextException.class);
	view.initApplicationContext();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AbstractJasperReportsViewTests.java

示例15: subReportWithUnspecifiedParentDataSource

import org.springframework.context.ApplicationContextException; //导入依赖的package包/类
@Test
public void subReportWithUnspecifiedParentDataSource() throws Exception {
	assumeTrue(canCompileReport);

	Map<String, Object> model = getModel();
	model.put("SubReportData", getProductData());

	Properties subReports = new Properties();
	subReports.put("ProductsSubReport", "org/springframework/ui/jasperreports/subReportChildFalse.jrxml");

	AbstractJasperReportsView view = getView(SUB_REPORT_PARENT);
	view.setSubReportUrls(subReports);
	view.setSubReportDataKeys(new String[]{"SubReportData"});

	// Unspecified reportDataKey should throw exception when subReportDataSources is specified
	exception.expect(ApplicationContextException.class);
	view.initApplicationContext();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:AbstractJasperReportsViewTests.java


注:本文中的org.springframework.context.ApplicationContextException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。