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

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

Introduction

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

Prototype

public BeanCreationException(String beanName, String msg) 

Source Link

Document

Create a new BeanCreationException.

Usage

From source file:com.github.mushkevych.genfabeto.Ganfabeto.java

public static Object createBean(String className, Map<String, Object> params) {
    try {/*from w  w w  .  j  av a  2s. co  m*/
        Object bean = createObject(className);
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            ReflectionTestUtils.setField(bean, entry.getKey(), entry.getValue());
        }
        return bean;
    } catch (ClassNotFoundException e) {
        String eMessage = String.format("Unable to find a class %s", className);
        log.error(eMessage, e);
        throw new BeanCreationException(eMessage, e);
    } catch (IllegalAccessException e) {
        String eMessage = String.format("Unable to access a class %s", className);
        log.error(eMessage, e);
        throw new BeanCreationException(eMessage, e);
    } catch (InstantiationException e) {
        String eMessage = String.format("Unable to instantiate a class %s", className);
        log.error(eMessage, e);
        throw new BeanCreationException(eMessage, e);
    }
}

From source file:com.netflix.spinnaker.kork.jedis.JedisHealthIndicatorFactory.java

public static HealthIndicator build(JedisClientDelegate client) {
    try {/*w w  w . j a v a 2 s. c  o  m*/
        final JedisClientDelegate src = client;
        final Field clientAccess = JedisClientDelegate.class.getDeclaredField("jedisPool");
        clientAccess.setAccessible(true);

        return build((Pool<Jedis>) clientAccess.get(src));
    } catch (IllegalAccessException | NoSuchFieldException e) {
        throw new BeanCreationException("Error creating Redis health indicator", e);
    }
}

From source file:com.consol.citrus.demo.voting.dao.JdbcApplicationConfig.java

@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnProperty(prefix = "voting.persistence", value = "server", havingValue = "enabled", matchIfMissing = true)
public Server database() {
    Server database = new Server();
    try {/*from w  w  w .java 2 s .c o  m*/
        database.setProperties(HsqlProperties.delimitedArgPairsToProps(
                "server.database.0=file:target/testdb;" + "server.dbname.0=testdb;" + "server.remote_open=true;"
                        + "server.port=18080;" + "hsqldb.reconfig_logging=false",
                "=", ";", null));
    } catch (IOException | ServerAcl.AclFormatException e) {
        throw new BeanCreationException("Failed to create embedded database storage", e);
    }
    return database;
}

From source file:com.netflix.spinnaker.kork.jedis.JedisHealthIndicatorFactory.java

public static HealthIndicator build(Pool<Jedis> jedisPool) {
    try {//from  ww w  . ja  v a  2 s.com
        final Pool<Jedis> src = jedisPool;
        final Field poolAccess = Pool.class.getDeclaredField("internalPool");
        poolAccess.setAccessible(true);
        GenericObjectPool<Jedis> internal = (GenericObjectPool<Jedis>) poolAccess.get(jedisPool);
        return () -> {
            Jedis jedis = null;
            Health.Builder health;
            try {
                jedis = src.getResource();
                if ("PONG".equals(jedis.ping())) {
                    health = Health.up();
                } else {
                    health = Health.down();
                }
            } catch (Exception ex) {
                health = Health.down(ex);
            } finally {
                if (jedis != null)
                    jedis.close();
            }
            health.withDetail("maxIdle", internal.getMaxIdle());
            health.withDetail("minIdle", internal.getMinIdle());
            health.withDetail("numActive", internal.getNumActive());
            health.withDetail("numIdle", internal.getNumIdle());
            health.withDetail("numWaiters", internal.getNumWaiters());

            return health.build();
        };
    } catch (IllegalAccessException | NoSuchFieldException e) {
        throw new BeanCreationException("Error creating Redis health indicator", e);
    }
}

From source file:com.consol.citrus.samples.todolist.config.HttpClientSslConfig.java

@Bean
public HttpClient httpClient() {
    try {//from w  w w  .  j  av  a 2 s .c  o  m
        SSLContext sslcontext = SSLContexts.custom()
                .loadTrustMaterial(new ClassPathResource("keys/citrus.jks").getFile(), "secret".toCharArray(),
                        new TrustSelfSignedStrategy())
                .build();

        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslcontext,
                NoopHostnameVerifier.INSTANCE);

        return HttpClients.custom().setSSLSocketFactory(sslSocketFactory)
                .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
    } catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException
            | KeyManagementException e) {
        throw new BeanCreationException("Failed to create http client for ssl connection", e);
    }
}

From source file:org.jsconf.core.impl.ProxyPostProcessor.java

public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
    if (bean.getClass().getInterfaces().length > 0) {
        BeanProxy proxy = this.proxyRef.get(beanName);
        if (proxy == null) {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            List<Class<?>> asList = new ArrayList<>();
            asList.addAll(Arrays.asList(bean.getClass().getInterfaces()));
            asList.add(BeanProxy.class);
            Class<?>[] interfaces = asList.toArray(new Class<?>[asList.size()]);
            proxy = (BeanProxy) Proxy.newProxyInstance(cl, interfaces, new ProxyHandler());
            this.proxyRef.put(beanName, proxy);
        }//from  ww w . j  av  a  2s. c  o m
        proxy.setBean(bean);
        return proxy;
    } else {
        throw new BeanCreationException(beanName,
                String.format("Only bean with interface can be proxy : %s", beanName));
    }
}

From source file:org.mule.ibeans.spring.IBeanInjectorsBeanPostProcessor.java

public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

    bean = ibeanAnnotationProcessor.process(bean);
    bean = injectDelegate.process(bean);
    Object service = applicationAnnotationsProcessor.process(bean);
    if (service instanceof Service) {
        try {//from  w  w w .j  av a2  s .  c om
            muleContext.getRegistry().registerService((Service) service);
        } catch (MuleException e) {
            throw new BeanCreationException("Failed to register iBeans service", e);
        }
    }
    return bean;
}

From source file:com.consol.citrus.samples.todolist.config.SoapClientSslConfig.java

@Bean
public HttpClient httpClient() {
    try {/*from w  ww.jav  a 2s .com*/
        SSLContext sslcontext = SSLContexts.custom()
                .loadTrustMaterial(new ClassPathResource("keys/citrus.jks").getFile(), "secret".toCharArray(),
                        new TrustSelfSignedStrategy())
                .build();

        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslcontext,
                NoopHostnameVerifier.INSTANCE);

        return HttpClients.custom().setSSLSocketFactory(sslSocketFactory)
                .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
                .addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor()).build();
    } catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException
            | KeyManagementException e) {
        throw new BeanCreationException("Failed to create http client for ssl connection", e);
    }
}

From source file:com.consol.citrus.samples.todolist.dao.JdbcApplicationConfig.java

@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnProperty(prefix = "todo.persistence", value = "server", havingValue = "enabled", matchIfMissing = true)
public Server database(JdbcConfigurationProperties configurationProperties) {
    Server database = new Server();
    try {// w w w.  jav  a2 s  .  co m
        HsqlProperties properties = new HsqlProperties();
        properties.setProperty("server.port", configurationProperties.getPort());
        properties.setProperty("server.database.0", configurationProperties.getFile());
        properties.setProperty("server.dbname.0", "testdb");
        properties.setProperty("server.remote_open", true);
        properties.setProperty("hsqldb.reconfig_logging", false);

        database.setProperties(properties);
    } catch (IOException | ServerAcl.AclFormatException e) {
        throw new BeanCreationException("Failed to create embedded database storage", e);
    }
    return database;
}

From source file:com.genius.admin.helper.MongoFactoryBean.java

private void replSeeds(String... serverAddresses) {
    try {/*ww  w. j a va 2 s.c o m*/
        replicaSetSeeds.clear();
        for (String addr : serverAddresses) {
            String[] a = addr.split(":");
            String host = a[0];
            if (a.length > 2) {
                throw new IllegalArgumentException("Invalid Server Address : " + addr);
            } else if (a.length == 2) {
                replicaSetSeeds.add(new ServerAddress(host, Integer.parseInt(a[1])));
            } else {
                replicaSetSeeds.add(new ServerAddress(host));
            }
        }
    } catch (Exception e) {
        throw new BeanCreationException("Error while creating replicaSetAddresses", e);
    }
}