Search in sources :

Example 1 with ApplicationContextException

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);
    }
}
Also used : ApplicationContextException(org.springframework.context.ApplicationContextException)

Example 2 with ApplicationContextException

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;
}
Also used : ArrayList(java.util.ArrayList) ApplicationListener(org.springframework.context.ApplicationListener) ApplicationEvent(org.springframework.context.ApplicationEvent) ApplicationContextException(org.springframework.context.ApplicationContextException) ApplicationContextException(org.springframework.context.ApplicationContextException)

Example 3 with ApplicationContextException

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();
}
Also used : ServletException(javax.servlet.ServletException) ServletWebServerFactory(org.springframework.boot.web.servlet.server.ServletWebServerFactory) WebServer(org.springframework.boot.web.server.WebServer) ServletContext(javax.servlet.ServletContext) ApplicationContextException(org.springframework.context.ApplicationContextException)

Example 4 with ApplicationContextException

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;
            }
        }
    }
}
Also used : ApplicationContextException(org.springframework.context.ApplicationContextException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 5 with ApplicationContextException

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 ");
                    }
                }
        }
    }
}
Also used : Field(org.apereo.portal.version.om.Version.Field) Version(org.apereo.portal.version.om.Version) ApplicationContextException(org.springframework.context.ApplicationContextException) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

ApplicationContextException (org.springframework.context.ApplicationContextException)20 IOException (java.io.IOException)5 Test (org.junit.Test)3 MockServletContext (org.springframework.mock.web.test.MockServletContext)3 ArrayList (java.util.ArrayList)2 MBeanServer (javax.management.MBeanServer)2 ObjectName (javax.management.ObjectName)2 ServletContextEvent (javax.servlet.ServletContextEvent)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 DirectoryContent (com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent)1 File (com.github.hakko.musiccabinet.domain.model.library.File)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ParseException (freemarker.core.ParseException)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 DirectoryIteratorException (java.nio.file.DirectoryIteratorException)1