Search in sources :

Example 66 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project midpoint by Evolveum.

the class WfConfiguration method initialize.

@PostConstruct
void initialize() {
    Configuration c = midpointConfiguration.getConfiguration(WF_CONFIG_SECTION);
    checkAllowedKeys(c, KNOWN_KEYS, DEPRECATED_KEYS);
    enabled = c.getBoolean(KEY_ENABLED, true);
    if (!enabled) {
        LOGGER.info("Workflows are disabled.");
        return;
    }
    // activiti properties related to database connection will be taken from SQL repository
    SqlRepositoryConfiguration sqlConfig = null;
    String defaultJdbcUrlPrefix = null;
    dropDatabase = false;
    try {
        RepositoryFactory repositoryFactory = (RepositoryFactory) beanFactory.getBean("repositoryFactory");
        if (!(repositoryFactory.getFactory() instanceof SqlRepositoryFactory)) {
            // it may be null as well
            LOGGER.debug("SQL configuration cannot be found; Activiti database configuration (if any) will be taken from 'workflow' configuration section only");
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("repositoryFactory.getFactory() = " + repositoryFactory);
            }
        } else {
            SqlRepositoryFactory sqlRepositoryFactory = (SqlRepositoryFactory) repositoryFactory.getFactory();
            sqlConfig = sqlRepositoryFactory.getSqlConfiguration();
            if (sqlConfig.isEmbedded()) {
                defaultJdbcUrlPrefix = sqlRepositoryFactory.prepareJdbcUrlPrefix(sqlConfig);
                dropDatabase = sqlConfig.isDropIfExists();
            }
        }
    } catch (NoSuchBeanDefinitionException e) {
        LOGGER.debug("SqlRepositoryFactory is not available, Activiti database configuration (if any) will be taken from 'workflow' configuration section only.");
        LOGGER.trace("Reason is", e);
    } catch (RepositoryServiceFactoryException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Cannot determine default JDBC URL for embedded database", e);
    }
    String explicitJdbcUrl = c.getString(KEY_JDBC_URL, null);
    if (explicitJdbcUrl == null) {
        if (sqlConfig == null || sqlConfig.isEmbedded()) {
            jdbcUrl = defaultJdbcUrlPrefix + "-activiti;DB_CLOSE_ON_EXIT=FALSE;MVCC=FALSE";
        } else {
            jdbcUrl = sqlConfig.getJdbcUrl();
        }
    } else {
        jdbcUrl = explicitJdbcUrl;
    }
    dataSource = c.getString(KEY_DATA_SOURCE, null);
    if (dataSource == null && explicitJdbcUrl == null && sqlConfig != null) {
        // we want to use wf-specific JDBC if there is one (i.e. we do not want to inherit data source from repo in such a case)
        dataSource = sqlConfig.getDataSource();
    }
    if (dataSource != null) {
        LOGGER.info("Activiti database is at " + dataSource + " (a data source)");
    } else {
        LOGGER.info("Activiti database is at " + jdbcUrl + " (a JDBC URL)");
    }
    boolean defaultSchemaUpdate = sqlConfig == null || "update".equals(sqlConfig.getHibernateHbm2ddl());
    activitiSchemaUpdate = c.getBoolean(KEY_ACTIVITI_SCHEMA_UPDATE, defaultSchemaUpdate);
    LOGGER.info("Activiti automatic schema update: {}", activitiSchemaUpdate);
    jdbcDriver = c.getString(KEY_JDBC_DRIVER, sqlConfig != null ? sqlConfig.getDriverClassName() : null);
    jdbcUser = c.getString(KEY_JDBC_USERNAME, sqlConfig != null ? sqlConfig.getJdbcUsername() : null);
    jdbcPassword = c.getString(KEY_JDBC_PASSWORD, sqlConfig != null ? sqlConfig.getJdbcPassword() : null);
    autoDeploymentFrom = c.getStringArray(KEY_AUTO_DEPLOYMENT_FROM);
    if (autoDeploymentFrom.length == 0) {
        autoDeploymentFrom = new String[] { AUTO_DEPLOYMENT_FROM_DEFAULT };
    }
    //        hibernateDialect = sqlConfig != null ? sqlConfig.getHibernateDialect() : "";
    validate();
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) Configuration(org.apache.commons.configuration.Configuration) SqlRepositoryConfiguration(com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration) SqlRepositoryFactory(com.evolveum.midpoint.repo.sql.SqlRepositoryFactory) SqlRepositoryFactory(com.evolveum.midpoint.repo.sql.SqlRepositoryFactory) RepositoryFactory(com.evolveum.midpoint.init.RepositoryFactory) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException) SqlRepositoryConfiguration(com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration) PostConstruct(javax.annotation.PostConstruct)

Example 67 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project cloudstack by apache.

the class NetworkStateListener method pubishOnEventBus.

private void pubishOnEventBus(String event, String status, Network vo, State oldState, State newState) {
    String configKey = "publish.resource.state.events";
    String value = _configDao.getValue(configKey);
    boolean configValue = Boolean.parseBoolean(value);
    if (!configValue)
        return;
    try {
        s_eventBus = ComponentContext.getComponent(EventBus.class);
    } catch (NoSuchBeanDefinitionException nbe) {
        // no provider is configured to provide events bus, so just return
        return;
    }
    String resourceName = getEntityFromClassName(Network.class.getName());
    org.apache.cloudstack.framework.events.Event eventMsg = new org.apache.cloudstack.framework.events.Event("management-server", EventCategory.RESOURCE_STATE_CHANGE_EVENT.getName(), event, resourceName, vo.getUuid());
    Map<String, String> eventDescription = new HashMap<String, String>();
    eventDescription.put("resource", resourceName);
    eventDescription.put("id", vo.getUuid());
    eventDescription.put("old-state", oldState.name());
    eventDescription.put("new-state", newState.name());
    String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
    eventDescription.put("eventDateTime", eventDate);
    eventMsg.setDescription(eventDescription);
    try {
        s_eventBus.publish(eventMsg);
    } catch (EventBusException e) {
        s_logger.warn("Failed to publish state change event on the the event bus.");
    }
}
Also used : HashMap(java.util.HashMap) EventBus(org.apache.cloudstack.framework.events.EventBus) Date(java.util.Date) Event(com.cloud.network.Network.Event) EventBusException(org.apache.cloudstack.framework.events.EventBusException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 68 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project engine by craftercms.

the class AllHttpScopesAndAppContextHashModel method get.

@Override
public TemplateModel get(String key) throws TemplateModelException {
    // Lookup in page scope
    TemplateModel model = super.get(key);
    if (model != null) {
        return model;
    }
    // Lookup in request scope
    Object obj = request.getAttribute(key);
    if (obj != null) {
        return wrap(obj);
    }
    // Lookup in session scope
    HttpSession session = request.getSession(false);
    if (session != null) {
        obj = session.getAttribute(key);
        if (obj != null) {
            return wrap(obj);
        }
    }
    // Lookup in application scope
    obj = context.getAttribute(key);
    if (obj != null) {
        return wrap(obj);
    }
    // Lookup in application context
    try {
        return wrap(applicationContextAccessor.get(key));
    } catch (NoSuchBeanDefinitionException e) {
    }
    // return wrapper's null object (probably null).
    return wrap(null);
}
Also used : HttpSession(javax.servlet.http.HttpSession) TemplateModel(freemarker.template.TemplateModel) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 69 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project uPortal by Jasig.

the class LdapServices method getLdapServer.

/**
 * Get the {@link ILdapServer} from the portal spring context with the specified name.
 *
 * @param name The name of the ILdapServer to return.
 * @return An {@link ILdapServer} with the specified name, <code>null</code> if there is no
 *     connection with the specified name.
 */
public static ILdapServer getLdapServer(String name) {
    final ApplicationContext applicationContext = PortalApplicationContextLocator.getApplicationContext();
    ILdapServer ldapServer = null;
    try {
        ldapServer = (ILdapServer) applicationContext.getBean(name, ILdapServer.class);
    } catch (NoSuchBeanDefinitionException nsbde) {
    // Ignore the exception for not finding the named bean.
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Found ILdapServer='" + ldapServer + "' for name='" + name + "'");
    }
    return ldapServer;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 70 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project ignite by apache.

the class IgniteSpringHelperImpl method userVersion.

/**
 * {@inheritDoc}
 */
@Override
public String userVersion(ClassLoader ldr, IgniteLogger log) {
    assert ldr != null;
    assert log != null;
    // For system class loader return cached version.
    if (ldr == U.gridClassLoader() && SYS_LDR_VER.get() != null)
        return SYS_LDR_VER.get();
    String usrVer = U.DFLT_USER_VERSION;
    InputStream in = ldr.getResourceAsStream(IGNITE_XML_PATH);
    if (in != null) {
        // Note: use ByteArrayResource instead of InputStreamResource because
        // InputStreamResource doesn't work.
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            U.copy(in, out);
            DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
            XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
            reader.loadBeanDefinitions(new ByteArrayResource(out.toByteArray()));
            usrVer = (String) factory.getBean("userVersion");
            usrVer = usrVer == null ? U.DFLT_USER_VERSION : usrVer.trim();
        } catch (NoSuchBeanDefinitionException ignored) {
            if (log.isInfoEnabled())
                log.info("User version is not explicitly defined (will use default version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']');
            usrVer = U.DFLT_USER_VERSION;
        } catch (BeansException e) {
            U.error(log, "Failed to parse Spring XML file (will use default user version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']', e);
            usrVer = U.DFLT_USER_VERSION;
        } catch (IOException e) {
            U.error(log, "Failed to read Spring XML file (will use default user version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']', e);
            usrVer = U.DFLT_USER_VERSION;
        } finally {
            U.close(out, log);
        }
    }
    // For system class loader return cached version.
    if (ldr == U.gridClassLoader())
        SYS_LDR_VER.compareAndSet(null, usrVer);
    return usrVer;
}
Also used : InputStream(java.io.InputStream) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayResource(org.springframework.core.io.ByteArrayResource) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) BeansException(org.springframework.beans.BeansException)

Aggregations

NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)71 Test (org.junit.Test)27 BeanCreationException (org.springframework.beans.factory.BeanCreationException)18 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)15 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)14 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)9 HashMap (java.util.HashMap)8 EventBus (org.apache.cloudstack.framework.events.EventBus)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 SimpleDateFormat (java.text.SimpleDateFormat)7 Date (java.util.Date)7 EventBusException (org.apache.cloudstack.framework.events.EventBusException)7 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)7 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)6 Method (java.lang.reflect.Method)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)5 ApplicationContext (org.springframework.context.ApplicationContext)5 ArrayList (java.util.ArrayList)4 Account (com.cloud.user.Account)3