Search in sources :

Example 1 with BeansException

use of org.springframework.beans.BeansException in project Asqatasun by Asqatasun.

the class AsqatasunCrawlJob method startContext.

/**
     * Start the context, catching and reporting any BeansExceptions.
     */
private void startContext(CrawlJob crawlJob) {
    LOGGER.debug("Starting context");
    PathSharingContext ac = crawlJob.getJobContext();
    ac.addApplicationListener(this);
    try {
        ac.start();
    } catch (BeansException be) {
        LOGGER.warn(be.getMessage());
        ac.close();
    } catch (Exception e) {
        LOGGER.warn(e.getMessage());
        try {
            ac.close();
        } catch (Exception e2) {
            e2.printStackTrace(System.err);
        } finally {
        }
    }
    LOGGER.debug("Context started");
}
Also used : PathSharingContext(org.archive.spring.PathSharingContext) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) CrawlerException(org.asqatasun.crawler.exception.CrawlerException) BeansException(org.springframework.beans.BeansException)

Example 2 with BeansException

use of org.springframework.beans.BeansException in project spring-framework by spring-projects.

the class WebApplicationContextFacesELResolver method getType.

@Override
public Class<?> getType(ELContext elContext, Object base, Object property) throws ELException {
    if (base != null) {
        if (base instanceof WebApplicationContext) {
            WebApplicationContext wac = (WebApplicationContext) base;
            String beanName = property.toString();
            if (logger.isDebugEnabled()) {
                logger.debug("Attempting to resolve property '" + beanName + "' in root WebApplicationContext");
            }
            if (wac.containsBean(beanName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Successfully resolved property '" + beanName + "' in root WebApplicationContext");
                }
                elContext.setPropertyResolved(true);
                try {
                    return wac.getType(beanName);
                } catch (BeansException ex) {
                    throw new ELException(ex);
                }
            } else {
                // Mimic standard JSF/JSP behavior when base is a Map by returning null.
                return null;
            }
        }
    } else {
        if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) {
            elContext.setPropertyResolved(true);
            return WebApplicationContext.class;
        }
    }
    return null;
}
Also used : ELException(javax.el.ELException) WebApplicationContext(org.springframework.web.context.WebApplicationContext) BeansException(org.springframework.beans.BeansException)

Example 3 with BeansException

use of org.springframework.beans.BeansException in project spring-framework by spring-projects.

the class WebApplicationContextFacesELResolver method getValue.

@Override
public Object getValue(ELContext elContext, Object base, Object property) throws ELException {
    if (base != null) {
        if (base instanceof WebApplicationContext) {
            WebApplicationContext wac = (WebApplicationContext) base;
            String beanName = property.toString();
            if (logger.isTraceEnabled()) {
                logger.trace("Attempting to resolve property '" + beanName + "' in root WebApplicationContext");
            }
            if (wac.containsBean(beanName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Successfully resolved property '" + beanName + "' in root WebApplicationContext");
                }
                elContext.setPropertyResolved(true);
                try {
                    return wac.getBean(beanName);
                } catch (BeansException ex) {
                    throw new ELException(ex);
                }
            } else {
                // Mimic standard JSF/JSP behavior when base is a Map by returning null.
                return null;
            }
        }
    } else {
        if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) {
            elContext.setPropertyResolved(true);
            return getWebApplicationContext(elContext);
        }
    }
    return null;
}
Also used : ELException(javax.el.ELException) WebApplicationContext(org.springframework.web.context.WebApplicationContext) BeansException(org.springframework.beans.BeansException)

Example 4 with BeansException

use of org.springframework.beans.BeansException in project spring-framework by spring-projects.

the class TestContextTransactionUtils method retrieveDataSource.

/**
	 * Retrieve the {@link DataSource} to use for the supplied {@linkplain TestContext
	 * test context}.
	 * <p>The following algorithm is used to retrieve the {@code DataSource} from
	 * the {@link org.springframework.context.ApplicationContext ApplicationContext}
	 * of the supplied test context:
	 * <ol>
	 * <li>Look up the {@code DataSource} by type and name, if the supplied
	 * {@code name} is non-empty, throwing a {@link BeansException} if the named
	 * {@code DataSource} does not exist.
	 * <li>Attempt to look up the single {@code DataSource} by type.
	 * <li>Attempt to look up the <em>primary</em> {@code DataSource} by type.
	 * <li>Attempt to look up the {@code DataSource} by type and the
	 * {@linkplain #DEFAULT_DATA_SOURCE_NAME default data source name}.
	 * @param testContext the test context for which the {@code DataSource}
	 * should be retrieved; never {@code null}
	 * @param name the name of the {@code DataSource} to retrieve; may be {@code null}
	 * or <em>empty</em>
	 * @return the {@code DataSource} to use, or {@code null} if not found
	 * @throws BeansException if an error occurs while retrieving an explicitly
	 * named {@code DataSource}
	 */
public static DataSource retrieveDataSource(TestContext testContext, String name) {
    Assert.notNull(testContext, "TestContext must not be null");
    BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory();
    try {
        // look up by type and explicit name
        if (StringUtils.hasText(name)) {
            return bf.getBean(name, DataSource.class);
        }
    } catch (BeansException ex) {
        logger.error(String.format("Failed to retrieve DataSource named '%s' for test context %s", name, testContext), ex);
        throw ex;
    }
    try {
        if (bf instanceof ListableBeanFactory) {
            ListableBeanFactory lbf = (ListableBeanFactory) bf;
            // look up single bean by type
            Map<String, DataSource> dataSources = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DataSource.class);
            if (dataSources.size() == 1) {
                return dataSources.values().iterator().next();
            }
            try {
                // look up single bean by type, with support for 'primary' beans
                return bf.getBean(DataSource.class);
            } catch (BeansException ex) {
                logBeansException(testContext, ex, PlatformTransactionManager.class);
            }
        }
        // look up by type and default name
        return bf.getBean(DEFAULT_DATA_SOURCE_NAME, DataSource.class);
    } catch (BeansException ex) {
        logBeansException(testContext, ex, DataSource.class);
        return null;
    }
}
Also used : BeanFactory(org.springframework.beans.factory.BeanFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) BeansException(org.springframework.beans.BeansException) DataSource(javax.sql.DataSource)

Example 5 with BeansException

use of org.springframework.beans.BeansException in project spring-framework by spring-projects.

the class TestContextTransactionUtils method retrieveTransactionManager.

/**
	 * Retrieve the {@linkplain PlatformTransactionManager transaction manager}
	 * to use for the supplied {@linkplain TestContext test context}.
	 * <p>The following algorithm is used to retrieve the transaction manager
	 * from the {@link org.springframework.context.ApplicationContext ApplicationContext}
	 * of the supplied test context:
	 * <ol>
	 * <li>Look up the transaction manager by type and explicit name, if the supplied
	 * {@code name} is non-empty, throwing a {@link BeansException} if the named
	 * transaction manager does not exist.
	 * <li>Attempt to look up the single transaction manager by type.
	 * <li>Attempt to look up the <em>primary</em> transaction manager by type.
	 * <li>Attempt to look up the transaction manager via a
	 * {@link TransactionManagementConfigurer}, if present.
	 * <li>Attempt to look up the transaction manager by type and the
	 * {@linkplain #DEFAULT_TRANSACTION_MANAGER_NAME default transaction manager
	 * name}.
	 * @param testContext the test context for which the transaction manager
	 * should be retrieved; never {@code null}
	 * @param name the name of the transaction manager to retrieve; may be
	 * {@code null} or <em>empty</em>
	 * @return the transaction manager to use, or {@code null} if not found
	 * @throws BeansException if an error occurs while retrieving an explicitly
	 * named transaction manager
	 * @throws IllegalStateException if more than one TransactionManagementConfigurer
	 * exists in the ApplicationContext
	 */
public static PlatformTransactionManager retrieveTransactionManager(TestContext testContext, String name) {
    Assert.notNull(testContext, "TestContext must not be null");
    BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory();
    try {
        // look up by type and explicit name
        if (StringUtils.hasText(name)) {
            return bf.getBean(name, PlatformTransactionManager.class);
        }
    } catch (BeansException ex) {
        logger.error(String.format("Failed to retrieve transaction manager named '%s' for test context %s", name, testContext), ex);
        throw ex;
    }
    try {
        if (bf instanceof ListableBeanFactory) {
            ListableBeanFactory lbf = (ListableBeanFactory) bf;
            // look up single bean by type
            Map<String, PlatformTransactionManager> txMgrs = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, PlatformTransactionManager.class);
            if (txMgrs.size() == 1) {
                return txMgrs.values().iterator().next();
            }
            try {
                // look up single bean by type, with support for 'primary' beans
                return bf.getBean(PlatformTransactionManager.class);
            } catch (BeansException ex) {
                logBeansException(testContext, ex, PlatformTransactionManager.class);
            }
            // look up single TransactionManagementConfigurer
            Map<String, TransactionManagementConfigurer> configurers = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, TransactionManagementConfigurer.class);
            Assert.state(configurers.size() <= 1, "Only one TransactionManagementConfigurer may exist in the ApplicationContext");
            if (configurers.size() == 1) {
                return configurers.values().iterator().next().annotationDrivenTransactionManager();
            }
        }
        // look up by type and default name
        return bf.getBean(DEFAULT_TRANSACTION_MANAGER_NAME, PlatformTransactionManager.class);
    } catch (BeansException ex) {
        logBeansException(testContext, ex, PlatformTransactionManager.class);
        return null;
    }
}
Also used : BeanFactory(org.springframework.beans.factory.BeanFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) TransactionManagementConfigurer(org.springframework.transaction.annotation.TransactionManagementConfigurer) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) BeansException(org.springframework.beans.BeansException)

Aggregations

BeansException (org.springframework.beans.BeansException)126 Test (org.junit.Test)24 ApplicationContext (org.springframework.context.ApplicationContext)22 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)13 BeanCreationException (org.springframework.beans.factory.BeanCreationException)11 HashMap (java.util.HashMap)10 BeanWrapper (org.springframework.beans.BeanWrapper)10 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)10 MalformedURLException (java.net.MalformedURLException)9 File (java.io.File)8 IOException (java.io.IOException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)8 List (java.util.List)7 Method (java.lang.reflect.Method)6 LinkedHashSet (java.util.LinkedHashSet)6