Example usage for org.springframework.beans.factory BeanDefinitionStoreException getBeanName

List of usage examples for org.springframework.beans.factory BeanDefinitionStoreException getBeanName

Introduction

In this page you can find the example usage for org.springframework.beans.factory BeanDefinitionStoreException getBeanName.

Prototype

@Nullable
public String getBeanName() 

Source Link

Document

Return the name of the bean, if available.

Usage

From source file:fr.paris.lutece.plugins.crmclient.business.CRMItemFactory.java

/**
 * {@inheritDoc}//  www  .j  a  v  a2 s .c o m
 */
@Override
public ICRMItem newCRMItem(String strBeanName) {
    if (StringUtils.isBlank(strBeanName)) {
        AppLogService.error("CRMItemFactory ERROR : The bean name is empty.");

        return null;
    }

    try {
        ICRMItem crmItem = SpringContextService.getBean(strBeanName);

        return crmItem;
    } catch (BeanDefinitionStoreException e) {
        AppLogService.error("CRMItemFactory ERROR : could not load bean '" + e.getBeanName() + "' - CAUSE : "
                + e.getMessage(), e);
    } catch (NoSuchBeanDefinitionException e) {
        AppLogService.error("CRMItemFactory ERROR : could not load bean '" + e.getBeanName() + "' - CAUSE : "
                + e.getMessage(), e);
    } catch (CannotLoadBeanClassException e) {
        AppLogService.error("CRMItemFactory ERROR : could not load bean '" + e.getBeanName() + "' - CAUSE : "
                + e.getMessage(), e);
    }

    return null;
}

From source file:fr.paris.lutece.plugins.workflow.modules.mappings.business.CodeMappingFactory.java

/**
 * {@inheritDoc}/*  w w  w  .java  2s.c o  m*/
 */
@Override
public ICodeMapping newCodeMapping(String strMappingTypeKey) {
    ICodeMapping codeMapping = null;

    try {
        codeMapping = SpringContextService.getBean(strMappingTypeKey);
    } catch (BeanDefinitionStoreException e) {
        AppLogService.debug("CodeMappingFactory ERROR : could not load bean '" + e.getBeanName()
                + "' - CAUSE : " + e.getMessage());
    } catch (NoSuchBeanDefinitionException e) {
        AppLogService.debug("CodeMappingFactory ERROR : could not load bean '" + e.getBeanName()
                + "' - CAUSE : " + e.getMessage());
    } catch (CannotLoadBeanClassException e) {
        AppLogService.debug("CodeMappingFactory ERROR : could not load bean '" + e.getBeanName()
                + "' - CAUSE : " + e.getMessage());
    }

    // If no mapping type is defined for strMappingTypeKey, then create a SimpleMappingType
    if (codeMapping == null) {
        codeMapping = new SimpleCodeMapping();
    }

    return codeMapping;
}

From source file:fr.paris.lutece.plugins.mylutece.modules.database.authentication.business.DatabaseUserFactory.java

/**
* Instanciate a new {@link DatabaseUser} defined in <b>database_context.xml</b>
* @return a new instance of {@link DatabaseUser}
*//*w  w w. ja v a  2s  .  co  m*/
public DatabaseUser newDatabaseUser() {
    DatabaseUser databaseUser = null;

    try {
        databaseUser = (DatabaseUser) SpringContextService.getBean(_strBeanDatabaseUser);
    } catch (BeanDefinitionStoreException e) {
        if (AppLogService.isDebugEnabled()) {
            AppLogService.debug("DatabaseUserFactory ERROR : could not load bean '" + e.getBeanName()
                    + "' - CAUSE : " + e.getMessage());
        }
    } catch (NoSuchBeanDefinitionException e) {
        if (AppLogService.isDebugEnabled()) {
            AppLogService.debug("DatabaseUserFactory ERROR : could not load bean '" + e.getBeanName()
                    + "' - CAUSE : " + e.getMessage());
        }
    } catch (CannotLoadBeanClassException e) {
        if (AppLogService.isDebugEnabled()) {
            AppLogService.debug("DatabaseUserFactory ERROR : could not load bean '" + e.getBeanName()
                    + "' - CAUSE : " + e.getMessage());
        }
    }

    // New DatabaseUser by default if the plugin cannot load the DatabaseUser by Spring 
    if (databaseUser == null) {
        databaseUser = new DatabaseUser();
    }

    return databaseUser;
}

From source file:fr.paris.lutece.plugins.workflow.service.task.TaskFactory.java

/**
 * {@inheritDoc}//w ww.  j  av a  2 s .c o m
 */
@Override
public ITaskConfig newTaskConfig(String strKey) {
    if (StringUtils.isBlank(strKey)) {
        AppLogService.error("TaskFactory ERROR : The key is empty.");

        return null;
    }

    Collection<ITaskType> listTaskType = getAllTaskTypes();

    for (ITaskType taskType : listTaskType) {
        if (strKey.equals(taskType.getKey())) {
            try {
                ITaskConfig config = SpringContextService.getBean(taskType.getConfigBeanName());

                return config;
            } catch (BeanDefinitionStoreException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            } catch (NoSuchBeanDefinitionException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            } catch (CannotLoadBeanClassException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            }
        }
    }

    AppLogService.error("TaskFactory ERROR : The task type is not found.");

    return null;
}

From source file:fr.paris.lutece.plugins.workflow.service.task.TaskFactory.java

/**
 * Get new instance of {@link ITask}/*from   w w w . j  a va 2s . co  m*/
 * @param strKey the task type key
 * @return a new instance of {@link ITask}
 */
private ITask newTask(String strKey) {
    if (StringUtils.isBlank(strKey)) {
        AppLogService.error("TaskFactory ERROR : The key is empty.");

        return null;
    }

    Collection<ITaskType> listTaskType = getAllTaskTypes();

    for (ITaskType taskType : listTaskType) {
        if (strKey.equals(taskType.getKey())) {
            try {
                ITask task = SpringContextService.getBean(taskType.getBeanName());
                task.setTaskType(taskType);

                return task;
            } catch (BeanDefinitionStoreException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            } catch (NoSuchBeanDefinitionException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            } catch (CannotLoadBeanClassException e) {
                AppLogService.error("TaskFactory ERROR : could not load bean '" + e.getBeanName()
                        + "' - CAUSE : " + e.getMessage(), e);
            }
        }
    }

    AppLogService.error("TaskFactory ERROR : The task type is not found.");

    return null;
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testNameAlreadyBound() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Properties p = new Properties();
    p.setProperty("kerry.(class)", TestBean.class.getName());
    p.setProperty("kerry.age", "35");
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
    try {/*from   w w  w  .  j  a  v  a2 s .  c o  m*/
        (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
    } catch (BeanDefinitionStoreException ex) {
        assertEquals("kerry", ex.getBeanName());
        // expected
    }
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testBeanDefinitionOverridingNotAllowed() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.setAllowBeanDefinitionOverriding(false);
    lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
    try {//from   w  w  w  . ja v a2 s . c o  m
        lbf.registerBeanDefinition("test", new RootBeanDefinition(NestedTestBean.class));
        fail("Should have thrown BeanDefinitionStoreException");
    } catch (BeanDefinitionStoreException ex) {
        assertEquals("test", ex.getBeanName());
        // expected
    }
}