Example usage for org.springframework.beans.factory BeanInitializationException BeanInitializationException

List of usage examples for org.springframework.beans.factory BeanInitializationException BeanInitializationException

Introduction

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

Prototype

public BeanInitializationException(String msg) 

Source Link

Document

Create a new BeanInitializationException with the specified message.

Usage

From source file:nats.client.spring.AnnotationConfigBeanPostProcessor.java

@Override
public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException {
    final Class<?> clazz = bean.getClass();
    for (final Method method : clazz.getMethods()) {
        final Subscribe annotation = AnnotationUtils.findAnnotation(method, Subscribe.class);
        if (annotation != null) {
            final Class<?>[] parameterTypes = method.getParameterTypes();
            if (parameterTypes.length != 1 || !parameterTypes[0].equals(Message.class)) {
                throw new BeanInitializationException(String.format(
                        "Method '%s' on bean with name '%s' must have a single parameter of type %s when using the @%s annotation.",
                        method.toGenericString(), beanName, Message.class.getName(),
                        Subscribe.class.getName()));
            }/*from   w w w. j  av a 2 s  . c  o m*/
            nats.subscribe(annotation.value()).addMessageHandler(new MessageHandler() {
                @Override
                public void onMessage(Message message) {
                    try {
                        method.invoke(bean, message);
                    } catch (IllegalAccessException e) {
                        throw new RuntimeException(e);
                    } catch (InvocationTargetException e) {
                        final Throwable targetException = e.getTargetException();
                        if (targetException instanceof RuntimeException) {
                            throw (RuntimeException) targetException;
                        }
                        throw new RuntimeException(targetException);
                    }
                }
            });
        }
    }

    return bean;
}

From source file:org.springdata.ehcache.config.EhcacheLookupFactoryBean.java

protected Ehcache lookupFallback(CacheManager cacheManager, String cacheName) {
    throw new BeanInitializationException(
            "Cannot find cache [" + cacheName + "] in terracotta " + cacheManager);
}

From source file:com.efficio.fieldbook.service.FileServiceImpl.java

public void init() {
    File file = new File(uploadDirectory);

    if (!file.exists()) {
        throw new BeanInitializationException("Specified upload directory does not exist : " + uploadDirectory);
    }/*  ww  w.jav  a2 s.c om*/
}

From source file:org.springdata.ehcache.mapping.BasicEhcachePersistentEntity.java

@SuppressWarnings("unchecked")
public BasicEhcachePersistentEntity(TypeInformation<T> typeInformation) {

    super(typeInformation);

    this.parser = new SpelExpressionParser();
    this.context = new StandardEvaluationContext();

    Class<T> rawType = typeInformation.getType();

    if (rawType.isAnnotationPresent(Entity.class)) {
        Entity annotation = rawType.getAnnotation(Entity.class);
        this.cacheName = StringUtils.hasText(annotation.cacheName()) ? annotation.cacheName() : null;
    } else {//w  w w . j av  a 2 s . c om
        this.cacheName = null;
    }

    if (this.cacheName == null) {
        throw new BeanInitializationException(
                "entity class " + rawType + " does not specify cache name by Cache annotation");
    }

    if (DataSerializable.class.isAssignableFrom(rawType)) {
        serializer = new DataSerializer<T>();
        deserializer = new DataDeserializer<T>(rawType);
    } else {
        serializer = (Serializer<T>) new DefaultSerializer();
        deserializer = (Deserializer<T>) new DefaultDeserializer();
    }

}

From source file:com.yy.kunka.core.workflow.processor.BaseProcessor.java

/**
 * Called after the properties have been set, Ensures the list of activities
 * is not empty and each activity is supported by this Workflow Processor.
 *
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 *//*w w  w.j a  v a 2  s .c  o m*/
@Override
public void afterPropertiesSet() throws Exception {

    if (!(beanFactory instanceof ListableBeanFactory)) {
        throw new BeanInitializationException("The workflow processor [" + beanName + "] "
                + "is not managed by a ListableBeanFactory, please re-deploy using some derivative of ListableBeanFactory such as"
                + "ClassPathXmlApplicationContext ");
    }

    if (CollectionUtils.isEmpty(activities) && !isAllowEmptyActivities()) {
        throw new UnsatisfiedDependencyException(getBeanDesc(), beanName, "activities",
                "No activities were wired for this workflow");
    }

    //sort the activities based on their configured order
    OrderComparator.sort(activities);
}

From source file:net.ggtools.maven.ddlgenerator.DDLGenerator.java

@PostConstruct
public void init() throws BeanInitializationException {
    // Check mandatory parameters.
    if (dialect == null) {
        log.error("Parameter 'dialect' is mandatory");
        throw new BeanInitializationException("Parameter 'dialect' is mandatory");
    }//from  w ww.j a  v a  2 s . c  o  m

    if (ddlFile == null) {
        log.error("Parameter 'ddlFile' is mandatory");
        throw new BeanInitializationException("Parameter 'ddlFile' is mandatory");
    }

    // Mandatory parameters
    configProperties.put("hibernate.dialect", dialect);

    // Optional parameters
    putIfNotNull("hibernate.default_schema", defaultSchema);
    putIfNotNull("hibernate.id.new_generator_mappings", useNewGenerator);
    putIfNotNull("hibernate.ejb.naming_strategy", namingStrategy);

    // Fixed values
    configProperties.put("hibernate.hbm2ddl.auto", "create");
    configProperties.put("hibernate.use_sql_comments", false);
    configProperties.put("hibernate.format_sql", false);
    configProperties.put("hibernate.show_sq", false);

    log.info("DDLGenerator configuration properties: " + configProperties);
}

From source file:com.btisystems.pronx.ems.model.MibInput.java

@Override
public final void afterPropertiesSet() throws Exception {

    // Check that source files have been defined in exactly one way.
    if (sourceDirectoryList != null) {
        if (sourceFilenames != null) {
            throw new BeanInitializationException(
                    "Cannot set both sourceFilenames and directoryName properties");
        }// w  ww  .  j a  v  a2s.c om
    } else if (sourceFilenames == null) {
        throw new BeanInitializationException("Neither sourceFilenames nor directoryName property set");
    }
}

From source file:org.archive.modules.deciderules.ScriptedDecideRule.java

public void afterPropertiesSet() throws Exception {
    // fail at build-time if script engine not available
    if (null == new ScriptEngineManager().getEngineByName(engineName)) {
        throw new BeanInitializationException("named ScriptEngine not available");
    }/*  www . jav  a  2s .co  m*/
}

From source file:org.constretto.spring.ConstrettoSingletonFactoryBean.java

/**
 * Chooses the correct implementation to use given the current environment. if no environment is set. uses the class
 * with the default prefix (production if not set)
 *//*  www . j  a v  a  2  s.co  m*/
public Object getObject() throws Exception {
    if (null == beans && null == defaultBean) {
        throw new BeanInitializationException("At least one implementation of the service is mandatory");
    }
    return getResolvedBean();
}

From source file:com.edgenius.wiki.search.service.TextExtractorService.java

public void afterPropertiesSet() throws Exception {
    if (extractors == null) {
        log.error("No any extractor inject, This Service won't work any more");
        throw new BeanInitializationException("No any extractor inject, This Service won't work any more");
    }//from  www. jav  a  2s. c  o  m
    for (String extractor : extractors) {
        TextExtractor ext = (TextExtractor) Class.forName(extractor).newInstance();
        extractorsInstances.add(ext);
    }
}