Search in sources :

Example 21 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project cas by apereo.

the class DuoSecurityAuthenticationEventExecutionPlanConfiguration method duoAuthenticationHandler.

@RefreshScope
@Bean
public AuthenticationHandler duoAuthenticationHandler() {
    final List<DuoSecurityMultifactorProperties> duos = casProperties.getAuthn().getMfa().getDuo();
    if (duos.isEmpty()) {
        throw new BeanCreationException("No configuration/settings could be found for Duo Security. Review settings and ensure the correct syntax is used");
    }
    final String name = duos.get(0).getName();
    if (duos.size() > 1) {
        LOGGER.debug("Multiple Duo Security providers are available; Duo authentication handler is named after [{}]", name);
    }
    final DuoAuthenticationHandler h = new DuoAuthenticationHandler(name, servicesManager, duoPrincipalFactory(), duoMultifactorAuthenticationProvider());
    return h;
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) DuoSecurityMultifactorProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorProperties) DuoAuthenticationHandler(org.apereo.cas.adaptors.duo.authn.DuoAuthenticationHandler) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 22 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project dubbo by alibaba.

the class ConfigTest method testMultiProtocolError.

@Test
public void testMultiProtocolError() {
    try {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-error.xml");
        ctx.start();
        ctx.stop();
        ctx.close();
    } catch (BeanCreationException e) {
        assertTrue(e.getMessage().contains("Found multi-protocols"));
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 23 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project cas by apereo.

the class MongoDbConnectionFactory method buildMongoDbClient.

private Mongo buildMongoDbClient(final BaseMongoDbProperties mongo) {
    if (StringUtils.isNotBlank(mongo.getClientUri())) {
        LOGGER.debug("Using MongoDb client URI [{}] to connect to MongoDb instance", mongo.getClientUri());
        return buildMongoDbClient(mongo.getClientUri(), buildMongoDbClientOptions(mongo));
    }
    final String[] serverAddresses = mongo.getHost().split(",");
    if (serverAddresses == null || serverAddresses.length == 0) {
        throw new BeanCreationException("Unable to build a MongoDb client without any hosts/servers defined");
    }
    List<ServerAddress> servers = new ArrayList<>();
    if (serverAddresses.length > 1) {
        LOGGER.debug("Multiple MongoDb server addresses are defined. Ignoring port [{}], " + "assuming ports are defined as part of the address", mongo.getPort());
        servers = Arrays.stream(serverAddresses).filter(StringUtils::isNotBlank).map(ServerAddress::new).collect(Collectors.toList());
    } else {
        final int port = mongo.getPort() > 0 ? mongo.getPort() : DEFAULT_PORT;
        LOGGER.debug("Found single MongoDb server address [{}] using port [{}]" + mongo.getHost(), port);
        final ServerAddress addr = new ServerAddress(mongo.getHost(), port);
        servers.add(addr);
    }
    final MongoCredential credential = buildMongoCredential(mongo);
    return new MongoClient(servers, CollectionUtils.wrap(credential), buildMongoDbClientOptions(mongo));
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) MongoClient(com.mongodb.MongoClient) MongoCredential(com.mongodb.MongoCredential) ServerAddress(com.mongodb.ServerAddress) ArrayList(java.util.ArrayList)

Example 24 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project cxf by apache.

the class SpringBeansTest method testEndpointWithUndefinedBus.

@Test
public void testEndpointWithUndefinedBus() throws Exception {
    try {
        new ClassPathXmlApplicationContext("/org/apache/cxf/jaxws/spring/endpoints3.xml").close();
        fail("Should have thrown an exception");
    } catch (BeanCreationException ex) {
        assertEquals("ep2", ex.getBeanName());
        assertTrue(ex.getMessage().contains("cxf1"));
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 25 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project openmrs-core by openmrs.

the class Listener method performWebStartOfModules.

public static void performWebStartOfModules(Collection<Module> startedModules, ServletContext servletContext) throws ModuleMustStartException, Exception {
    boolean someModuleNeedsARefresh = false;
    for (Module mod : startedModules) {
        try {
            boolean thisModuleCausesRefresh = WebModuleUtil.startModule(mod, servletContext, /* delayContextRefresh */
            true);
            someModuleNeedsARefresh = someModuleNeedsARefresh || thisModuleCausesRefresh;
        } catch (Exception e) {
            mod.setStartupErrorMessage("Unable to start module", e);
        }
    }
    if (someModuleNeedsARefresh) {
        try {
            WebModuleUtil.refreshWAC(servletContext, true, null);
        } catch (ModuleMustStartException | BeanCreationException ex) {
            // pass this up to the calling method so that openmrs loading stops
            throw ex;
        } catch (Exception e) {
            Throwable rootCause = getActualRootCause(e, true);
            if (rootCause != null) {
                log.error(MarkerFactory.getMarker("FATAL"), "Unable to refresh the spring application context.  Root Cause was:", rootCause);
            } else {
                log.error(MarkerFactory.getMarker("FATAL"), "nable to refresh the spring application context. Unloading all modules,  Error was:", e);
            }
            try {
                WebModuleUtil.shutdownModules(servletContext);
                for (Module mod : ModuleFactory.getLoadedModules()) {
                    // use loadedModules to avoid a concurrentmodificationexception
                    if (!mod.isCoreModule() && !mod.isMandatory()) {
                        try {
                            ModuleFactory.stopModule(mod, true, true);
                        } catch (Exception t3) {
                            // just keep going if we get an error shutting down.  was probably caused by the module
                            // that actually got us to this point!
                            log.trace("Unable to shutdown module:" + mod, t3);
                        }
                    }
                }
                WebModuleUtil.refreshWAC(servletContext, true, null);
            } catch (MandatoryModuleException ex) {
                // pass this up to the calling method so that openmrs loading stops
                throw new MandatoryModuleException(ex.getModuleId(), "Got an error while starting a mandatory module: " + e.getMessage() + ". Check the server logs for more information");
            } catch (Exception t2) {
                // a mandatory or core module is causing spring to fail to start up.  We don't want those
                // stopped so we must report this error to the higher authorities
                log.warn("caught another error: ", t2);
                throw t2;
            }
        }
    }
    // (this is to protect servlets/filters that depend on their module's spring xml config being available)
    for (Module mod : ModuleFactory.getStartedModules()) {
        WebModuleUtil.loadServlets(mod, servletContext);
        WebModuleUtil.loadFilters(mod, servletContext);
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ModuleMustStartException(org.openmrs.module.ModuleMustStartException) Module(org.openmrs.module.Module) MandatoryModuleException(org.openmrs.module.MandatoryModuleException) ServletException(javax.servlet.ServletException) DatabaseUpdateException(org.openmrs.util.DatabaseUpdateException) InputRequiredException(org.openmrs.util.InputRequiredException) ModuleMustStartException(org.openmrs.module.ModuleMustStartException) OpenmrsCoreModuleException(org.openmrs.module.OpenmrsCoreModuleException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) MandatoryModuleException(org.openmrs.module.MandatoryModuleException) IOException(java.io.IOException)

Aggregations

BeanCreationException (org.springframework.beans.factory.BeanCreationException)133 Test (org.junit.Test)30 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)18 BeansException (org.springframework.beans.BeansException)16 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 IOException (java.io.IOException)12 Map (java.util.Map)12 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 Test (org.junit.jupiter.api.Test)11 HashMap (java.util.HashMap)9 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)9 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)8 ArrayList (java.util.ArrayList)7 PostConstruct (javax.annotation.PostConstruct)7 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)7 Bean (org.springframework.context.annotation.Bean)7 HasId (org.apache.camel.spi.HasId)6 BeanCurrentlyInCreationException (org.springframework.beans.factory.BeanCurrentlyInCreationException)6 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)6 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)5