List of usage examples for org.springframework.beans BeanInstantiationException BeanInstantiationException
public BeanInstantiationException(Class<?> beanClass, String msg)
From source file:com.frank.search.solr.server.support.SolrClientUtils.java
/** * Create a clone of given {@link org.apache.solr.client.solrj.SolrClient} * and modify baseUrl of clone to point to the given core. * * @param solrClient/*from w w w .ja va2 s .co m*/ * Non null reference * {@link org.apache.solr.client.solrj.SolrClient} to copy * properties from. * @param core * Name of solr core to point to. * @return * @throws org.springframework.beans.BeanInstantiationException * if creating instance failed */ @SuppressWarnings("unchecked") public static <T extends SolrClient> T clone(T solrClient, String core) { Assert.notNull(solrClient); String shortName = getSolrClientTypeName(solrClient); if (shortName.equals("SolrClient")) { // cannot create instance of // abstract class, return solrClient; } SolrClient clone = null; if (shortName.equals("HttpSolrClient")) { clone = cloneHttpSolrClient(solrClient, core); } else if (shortName.equals("LBHttpSolrClient")) { clone = cloneLBHttpSolrClient(solrClient, core); } else if (shortName.equals("CloudSolrClient")) { clone = cloneCloudSolrClient(solrClient, core); } else if (shortName.equals("EmbeddedSolrServer")) { clone = cloneEmbeddedSolrServer(solrClient, core); } if (clone == null) { throw new BeanInstantiationException(solrClient.getClass(), "Cannot create instace of " + shortName + "."); } copyProperties(solrClient, clone); return (T) clone; }
From source file:org.constretto.spring.ConfigurationAnnotationConfigurer.java
private void injectEnvironment(final Object bean) { try {/*from ww w .j a v a 2s .com*/ Field[] fields = bean.getClass().getDeclaredFields(); for (Field field : fields) { if (field.isAnnotationPresent(Environment.class)) { field.setAccessible(true); field.set(bean, assemblyContextResolver.getAssemblyContext()); } } } catch (IllegalAccessException e) { throw new BeanInstantiationException(bean.getClass(), "Could not inject Environment on spring bean"); } }
From source file:org.jasig.cas.ticket.registry.EhCacheTicketRegistry.java
@Override public void afterPropertiesSet() throws Exception { if (this.serviceTicketsCache == null || this.ticketGrantingTicketsCache == null) { throw new BeanInstantiationException(this.getClass(), "Both serviceTicketsCache and ticketGrantingTicketsCache are required properties."); }//w w w.j a v a 2s.co m if (logger.isDebugEnabled()) { CacheConfiguration config = this.serviceTicketsCache.getCacheConfiguration(); logger.debug("serviceTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap()); logger.debug("serviceTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk()); logger.debug("serviceTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk()); logger.debug("serviceTicketsCache.timeToLive={}", config.getTimeToLiveSeconds()); logger.debug("serviceTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds()); logger.debug("serviceTicketsCache.cacheManager={}", this.serviceTicketsCache.getCacheManager().getName()); config = this.ticketGrantingTicketsCache.getCacheConfiguration(); logger.debug("ticketGrantingTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap()); logger.debug("ticketGrantingTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk()); logger.debug("ticketGrantingTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk()); logger.debug("ticketGrantingTicketsCache.timeToLive={}", config.getTimeToLiveSeconds()); logger.debug("ticketGrantingTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds()); logger.debug("ticketGrantingTicketsCache.cacheManager={}", this.ticketGrantingTicketsCache.getCacheManager().getName()); } }
From source file:org.springframework.beans.BeanUtils.java
/** * Convenience method to instantiate a class using its no-arg constructor. * @param clazz class to instantiate//from w w w . j a v a 2 s . co m * @return the new instance * @throws BeanInstantiationException if the bean cannot be instantiated * @deprecated as of Spring 5.0, following the deprecation of * {@link Class#newInstance()} in JDK 9 * @see Class#newInstance() */ @Deprecated public static <T> T instantiate(Class<T> clazz) throws BeanInstantiationException { Assert.notNull(clazz, "Class must not be null"); if (clazz.isInterface()) { throw new BeanInstantiationException(clazz, "Specified class is an interface"); } try { return clazz.newInstance(); } catch (InstantiationException ex) { throw new BeanInstantiationException(clazz, "Is it an abstract class?", ex); } catch (IllegalAccessException ex) { throw new BeanInstantiationException(clazz, "Is the constructor accessible?", ex); } }
From source file:org.springframework.beans.BeanUtils.java
/** * Instantiate a class using its 'primary' constructor (for Kotlin classes, * potentially having default arguments declared) or its default constructor * (for regular Java classes, expecting a standard no-arg setup). * <p>Note that this method tries to set the constructor accessible * if given a non-accessible (that is, non-public) constructor. * @param clazz the class to instantiate * @return the new instance/*from w ww . j a v a 2 s. co m*/ * @throws BeanInstantiationException if the bean cannot be instantiated. * The cause may notably indicate a {@link NoSuchMethodException} if no * primary/default constructor was found, a {@link NoClassDefFoundError} * or other {@link LinkageError} in case of an unresolvable class definition * (e.g. due to a missing dependency at runtime), or an exception thrown * from the constructor invocation itself. * @see Constructor#newInstance */ public static <T> T instantiateClass(Class<T> clazz) throws BeanInstantiationException { Assert.notNull(clazz, "Class must not be null"); if (clazz.isInterface()) { throw new BeanInstantiationException(clazz, "Specified class is an interface"); } try { Constructor<T> ctor = (KotlinDetector.isKotlinType(clazz) ? KotlinDelegate.getPrimaryConstructor(clazz) : clazz.getDeclaredConstructor()); return instantiateClass(ctor); } catch (NoSuchMethodException ex) { throw new BeanInstantiationException(clazz, "No default constructor found", ex); } catch (LinkageError err) { throw new BeanInstantiationException(clazz, "Unresolvable class definition", err); } }
From source file:org.springframework.data.solr.server.support.SolrServerUtils.java
/** * Create a clone of given {@link SolrServer} and modify baseUrl of clone to point to the given core. * /* w ww. j a va 2s . c o m*/ * @param solrServer Non null reference {@link SolrServer} to copy properties from. * @param core Name of solr core to point to. * @return * @throws BeanInstantiationException if creating instance failed */ @SuppressWarnings("unchecked") public static <T extends SolrServer> T clone(T solrServer, String core) { Assert.notNull(solrServer); String shortName = getSolrServerTypeName(solrServer); if (shortName.equals("SolrServer")) { // cannot create instance of interface, return solrServer; } SolrServer clone = null; if (shortName.equals("HttpSolrServer") || shortName.equals("CommonsHttpSolrServer")) { clone = cloneHttpSolrServer(solrServer, core); } else if (shortName.equals("LBHttpSolrServer")) { clone = cloneLBHttpSolrServer(solrServer, core); } else if (shortName.equals("CloudSolrServer")) { clone = cloneCloudSolrServer(solrServer, core); } else if (shortName.equals("EmbeddedSolrServer")) { clone = cloneEmbeddedSolrServer(solrServer, core); } if (clone == null) { throw new BeanInstantiationException(solrServer.getClass(), "Cannot create instace of " + shortName + "."); } copyProperties(solrServer, clone); return (T) clone; }