List of usage examples for org.springframework.context ApplicationContextException ApplicationContextException
public ApplicationContextException(String msg)
From source file:com.ebay.pulsar.metric.server.MetricDispatcherServlet.java
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 + "]"); }/*from w w w. ja v a 2 s .c o m*/ 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.setParent(parent); if (wac.getParent() == null) { ApplicationContext rootContext = (ApplicationContext) getServletContext().getAttribute("JetStreamRoot"); wac.setParent(rootContext); } wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); return wac; }
From source file:com.betfair.tornjak.monitor.overlay.AuthUtils.java
private static synchronized RolePerms getOrCreateRolePerms(ServletContext servletContext) throws IOException { RolePerms rolePerms;//w ww.j a v a2 s . co m rolePerms = (RolePerms) servletContext.getAttribute(CONTEXT_ATTR_NAME); if (rolePerms != null) { return rolePerms; } ApplicationContext context = (ApplicationContext) servletContext .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (context == null) { throw new ApplicationContextException("Unable to find application context"); } String authFileLocation = servletContext.getInitParameter(CONTEXT_INIT_PARAM_NAME); if (StringUtils.isBlank(authFileLocation)) { throw new ApplicationContextException(String .format("Parameter '%s' not defined, unable to load jmx auth file", CONTEXT_INIT_PARAM_NAME)); } rolePerms = AuthFileReader.load(context.getResource(authFileLocation)); servletContext.setAttribute(CONTEXT_ATTR_NAME, rolePerms); return rolePerms; }
From source file:com.jklas.sample.petclinic.web.ClinicController.java
public void afterPropertiesSet() throws Exception { if (clinic == null) throw new ApplicationContextException("Must set clinic bean property on " + getClass()); }
From source file:com.helpinput.spring.servlet.mvc.EnhanceDispachServlet.java
@Override protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { ContextHolder.beanRegistIntercpterHolder.register(new UrlInterceptorBeanRegistInterceptor()); Class<?> contextClass = getContextClass(); if (logger.isDebugEnabled()) { logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + contextClass.getName() + "'" + ", using parent context [" + parent + "]"); }/* w w w. ja v a 2s . c o m*/ 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; if (parent instanceof ConfigurableWebApplicationContext) wac = (ConfigurableWebApplicationContext) parent; else { wac = (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass); wac.setEnvironment(getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); } return wac; }
From source file:org.carewebframework.api.AppFramework.java
/** * ApplicationContextAware interface to allow container to inject itself. Sets the active * application context./* www .jav a2 s . c om*/ * * @param appContext The active application context. */ @Override public void setApplicationContext(ApplicationContext appContext) throws BeansException { if (this.appContext != null) { throw new ApplicationContextException("Attempt to reinitialize application context."); } this.appContext = appContext; }
From source file:com.googlecode.ehcache.annotations.examples.impl.SpringJdbcWeatherServiceImpl.java
public void afterPropertiesSet() throws Exception { if (null == this.simpleJdbcTemplate) { throw new ApplicationContextException("dataSource is required"); }/*from ww w .ja v a2 s . c om*/ this.simpleJdbcTemplate.getJdbcOperations() .execute("CREATE TABLE WEATHER (ZIPCODE varchar (10) NOT NULL, CURRENT_TEMP real not null)"); }
From source file:org.beanlet.springframework.impl.SpringHelper.java
public static synchronized ListableBeanFactory getListableBeanFactory(BeanletConfiguration<?> configuration, Element element) {//from ww w .j av a2s . c o m SpringContext springContext = getSpringContext(configuration, element); if (springContext == null) { throw new ApplicationContextException("No spring context specified."); } final ClassLoader loader = configuration.getComponentUnit().getClassLoader(); Map<SpringContext, ListableBeanFactory> map = factories.get(loader); if (map == null) { map = new HashMap<SpringContext, ListableBeanFactory>(); factories.put(loader, map); } ListableBeanFactory factory = map.get(springContext); if (factory == null) { ClassLoader org = null; try { org = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { // PERMISSION: java.lang.RuntimePermission getClassLoader ClassLoader org = Thread.currentThread().getContextClassLoader(); // PERMISSION: java.lang.RuntimePermission setContextClassLoader Thread.currentThread().setContextClassLoader(loader); return org; } }); if (springContext.applicationContext()) { factory = new GenericApplicationContext(); } else { factory = new DefaultListableBeanFactory(); } // Do not create spring context in priviliged scope! for (SpringResource r : springContext.value()) { String path = r.value(); Resource resource = null; BeanDefinitionReader reader = null; switch (r.type()) { case CLASSPATH: resource = new ClassPathResource(path); break; case FILESYSTEM: resource = new FileSystemResource(path); break; case URL: resource = new UrlResource(path); break; default: assert false : r.type(); } switch (r.format()) { case XML: reader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) factory); break; case PROPERTIES: reader = new PropertiesBeanDefinitionReader((BeanDefinitionRegistry) factory); break; default: assert false : r.format(); } if (resource != null && resource.exists()) { reader.loadBeanDefinitions(resource); } } if (factory instanceof ConfigurableApplicationContext) { ((ConfigurableApplicationContext) factory).refresh(); } map.put(springContext, factory); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new ApplicationContextException("Failed to construct spring " + (springContext.applicationContext() ? "application context" : "bean factory") + ".", e); } finally { final ClassLoader tmp = org; AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { // PERMISSION: java.lang.RuntimePermission setContextClassLoader Thread.currentThread().setContextClassLoader(tmp); return null; } }); } } return factory; }
From source file:com.baifendian.swordfish.dao.datasource.DatabaseConfiguration.java
/** * ??//w w w . j ava2s . co m */ @Primary @Bean(name = "DataSource", initMethod = "init", destroyMethod = "close") public DruidDataSource dataSource() throws SQLException { if (StringUtils.isEmpty(env.getProperty("spring.datasource.url"))) { logger.error( "Your database connection pool configuration is incorrect! Please check your Spring profile, " + "current profiles are: {}", Arrays.toString(env.getActiveProfiles())); throw new ApplicationContextException("Database connection pool is not configured correctly"); } DruidDataSource druidDataSource = new DruidDataSource(); druidDataSource.setDriverClassName(env.getProperty("spring.datasource.driver-class-name")); druidDataSource.setUrl(env.getProperty("spring.datasource.url")); druidDataSource.setUsername(env.getProperty("spring.datasource.username")); druidDataSource.setPassword(env.getProperty("spring.datasource.password")); druidDataSource.setInitialSize(Integer.parseInt(env.getProperty("spring.datasource.initialSize"))); druidDataSource.setMinIdle(Integer.parseInt(env.getProperty("spring.datasource.minIdle"))); druidDataSource.setMaxActive(Integer.parseInt(env.getProperty("spring.datasource.maxActive"))); druidDataSource.setMaxWait(Integer.parseInt(env.getProperty("spring.datasource.maxWait"))); druidDataSource.setTimeBetweenEvictionRunsMillis( Long.parseLong(env.getProperty("spring.datasource.timeBetweenEvictionRunsMillis"))); druidDataSource.setMinEvictableIdleTimeMillis( Long.parseLong(env.getProperty("spring.datasource.minEvictableIdleTimeMillis"))); druidDataSource.setValidationQuery(env.getProperty("spring.datasource.validationQuery")); druidDataSource.setTestWhileIdle(Boolean.parseBoolean(env.getProperty("spring.datasource.testWhileIdle"))); druidDataSource.setTestOnBorrow(Boolean.parseBoolean(env.getProperty("spring.datasource.testOnBorrow"))); druidDataSource.setTestOnReturn(Boolean.parseBoolean(env.getProperty("spring.datasource.testOnReturn"))); druidDataSource.setPoolPreparedStatements( Boolean.parseBoolean(env.getProperty("spring.datasource.poolPreparedStatements"))); druidDataSource.setMaxPoolPreparedStatementPerConnectionSize( Integer.parseInt(env.getProperty("spring.datasource.maxPoolPreparedStatementPerConnectionSize"))); druidDataSource.setFilters(env.getProperty("spring.datasource.filters")); return druidDataSource; }
From source file:org.zilverline.web.ZilverController.java
/** * Checks whether we have a collectionManager. * /*from w w w . ja v a 2 s . c o m*/ * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ public void afterPropertiesSet() { if (collectionManager == null) { throw new ApplicationContextException("Must set collectionManager bean property on " + getClass()); } }
From source file:fi.helsinki.opintoni.config.DatabaseConfiguration.java
@Bean public DataSource dataSource() { log.debug("Configuring Datasource"); if (propertyResolver.getProperty("url") == null && propertyResolver.getProperty("databaseName") == null) { log.error(// www .ja va 2 s. c o m "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(propertyResolver.getProperty("dataSourceClassName")); if (propertyResolver.getProperty("url") == null || "".equals(propertyResolver.getProperty("url"))) { config.addDataSourceProperty("databaseName", propertyResolver.getProperty("databaseName")); config.addDataSourceProperty("serverName", propertyResolver.getProperty("serverName")); } else { config.addDataSourceProperty("url", propertyResolver.getProperty("url")); } config.addDataSourceProperty("user", propertyResolver.getProperty("username")); config.addDataSourceProperty("password", propertyResolver.getProperty("password")); if (metricRegistry != null) { config.setMetricRegistry(metricRegistry); } return new HikariDataSource(config); }