use of org.springframework.context.ApplicationContextException in project spring-boot by spring-projects.
the class DelegatingApplicationContextInitializer method getInitializerClass.
private Class<?> getInitializerClass(String className) throws LinkageError {
try {
Class<?> initializerClass = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
Assert.isAssignable(ApplicationContextInitializer.class, initializerClass);
return initializerClass;
} catch (ClassNotFoundException ex) {
throw new ApplicationContextException("Failed to load context initializer class [" + className + "]", ex);
}
}
use of org.springframework.context.ApplicationContextException in project spring-boot by spring-projects.
the class DelegatingApplicationListener method getListeners.
@SuppressWarnings("unchecked")
private List<ApplicationListener<ApplicationEvent>> getListeners(ConfigurableEnvironment environment) {
if (environment == null) {
return Collections.emptyList();
}
String classNames = environment.getProperty(PROPERTY_NAME);
List<ApplicationListener<ApplicationEvent>> listeners = new ArrayList<>();
if (StringUtils.hasLength(classNames)) {
for (String className : StringUtils.commaDelimitedListToSet(classNames)) {
try {
Class<?> clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
Assert.isAssignable(ApplicationListener.class, clazz, "class [" + className + "] must implement ApplicationListener");
listeners.add((ApplicationListener<ApplicationEvent>) BeanUtils.instantiateClass(clazz));
} catch (Exception ex) {
throw new ApplicationContextException("Failed to load context listener class [" + className + "]", ex);
}
}
}
AnnotationAwareOrderComparator.sort(listeners);
return listeners;
}
use of org.springframework.context.ApplicationContextException in project spring-boot by spring-projects.
the class ServletWebServerApplicationContext method createWebServer.
private void createWebServer() {
WebServer webServer = this.webServer;
ServletContext servletContext = getServletContext();
if (webServer == null && servletContext == null) {
ServletWebServerFactory factory = getWebServerFactory();
this.webServer = factory.getWebServer(getSelfInitializer());
} else if (servletContext != null) {
try {
getSelfInitializer().onStartup(servletContext);
} catch (ServletException ex) {
throw new ApplicationContextException("Cannot initialize servlet context", ex);
}
}
initPropertySources();
}
use of org.springframework.context.ApplicationContextException in project spring-framework by spring-projects.
the class LiveBeansView method unregisterApplicationContext.
static void unregisterApplicationContext(ConfigurableApplicationContext applicationContext) {
synchronized (applicationContexts) {
if (applicationContexts.remove(applicationContext) && applicationContexts.isEmpty()) {
try {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
String mbeanDomain = applicationContext.getEnvironment().getProperty(MBEAN_DOMAIN_PROPERTY_NAME);
server.unregisterMBean(new ObjectName(mbeanDomain, MBEAN_APPLICATION_KEY, applicationName));
} catch (Throwable ex) {
throw new ApplicationContextException("Failed to unregister LiveBeansView MBean", ex);
} finally {
applicationName = null;
}
}
}
}
use of org.springframework.context.ApplicationContextException in project uPortal by Jasig.
the class VersionVerifier method afterPropertiesSet.
@SuppressWarnings("FallThrough")
@Override
public void afterPropertiesSet() throws Exception {
for (final Map.Entry<String, Version> productVersionEntry : this.requiredProductVersions.entrySet()) {
final String product = productVersionEntry.getKey();
final Version dbVersion = this.versionDao.getVersion(product);
if (dbVersion == null) {
throw new ApplicationContextException("No Version exists for " + product + " in the database. Please check the upgrade instructions for this release.");
}
final Version codeVersion = productVersionEntry.getValue();
final Field mostSpecificMatchingField = VersionUtils.getMostSpecificMatchingField(dbVersion, codeVersion);
switch(mostSpecificMatchingField) {
// Versions completely match
case LOCAL:
{
logger.info("Software and Database versions are both {} for {}", dbVersion, product);
continue;
}
// Versions match except for local part
case PATCH:
// Versions match except for patch.local part
case MINOR:
{
// If db is before code and auto-update is enabled run hibernate-update
final Field upgradeField = mostSpecificMatchingField.getLessImportant();
if (dbVersion.isBefore(codeVersion) && this.updatePolicy != null && (upgradeField.equals(this.updatePolicy) || upgradeField.isLessImportantThan(this.updatePolicy))) {
logger.info("Automatically updating database from {} to {} for {}", dbVersion, codeVersion, product);
this.portalShellBuildHelper.hibernateUpdate("automated-hibernate-update", product, true, null);
continue;
} else if (codeVersion.isBefore(dbVersion)) {
// It is ok to run older code on a newer DB within the local/patch range
continue;
}
}
// Versions match except for minor.patch.local part
case MAJOR:
// Versions do not match at all
default:
{
if (dbVersion.isBefore(codeVersion)) {
throw new ApplicationContextException("Database Version for " + product + " is " + dbVersion + " but the code version is " + codeVersion + ". Please check the upgrade instructions for this release");
} else {
throw new ApplicationContextException("Database Version for " + product + " is " + dbVersion + " but the code version is " + codeVersion + ". It is not possible to run ");
}
}
}
}
}
Aggregations