Java Code Examples for org.springframework.beans.BeansException#getMessage()
The following examples show how to use
org.springframework.beans.BeansException#getMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteSpringHelperImpl.java From ignite with Apache License 2.0 | 6 votes |
/** * Creates Spring application context. Optionally excluded properties can be specified, * it means that if such a property is found in {@link org.apache.ignite.configuration.IgniteConfiguration} * then it is removed before the bean is instantiated. * For example, {@code streamerConfiguration} can be excluded from the configs that Visor uses. * * @param cfgStream Stream where config file is located. * @param excludedProps Properties to be excluded. * @return Spring application context. * @throws IgniteCheckedException If configuration could not be read. */ public static ApplicationContext applicationContext(InputStream cfgStream, final String... excludedProps) throws IgniteCheckedException { try { GenericApplicationContext springCtx = prepareSpringContext(excludedProps); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(springCtx); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new InputStreamResource(cfgStream)); springCtx.refresh(); return springCtx; } catch (BeansException e) { if (X.hasCause(e, ClassNotFoundException.class)) throw new IgniteCheckedException("Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) ", e); else throw new IgniteCheckedException("Failed to instantiate Spring XML application context [err=" + e.getMessage() + ']', e); } }
Example 2
Source File: IgniteSpringHelperImpl.java From ignite with Apache License 2.0 | 6 votes |
/** * Creates Spring application context. Optionally excluded properties can be specified, * it means that if such a property is found in {@link org.apache.ignite.configuration.IgniteConfiguration} * then it is removed before the bean is instantiated. * For example, {@code streamerConfiguration} can be excluded from the configs that Visor uses. * * @param cfgUrl Resource where config file is located. * @param excludedProps Properties to be excluded. * @return Spring application context. * @throws IgniteCheckedException If configuration could not be read. */ public static ApplicationContext applicationContext(URL cfgUrl, final String... excludedProps) throws IgniteCheckedException { try { GenericApplicationContext springCtx = prepareSpringContext(excludedProps); new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(cfgUrl)); springCtx.refresh(); return springCtx; } catch (BeansException e) { if (X.hasCause(e, ClassNotFoundException.class)) throw new IgniteCheckedException("Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) " + "[springUrl=" + cfgUrl + ']', e); else throw new IgniteCheckedException("Failed to instantiate Spring XML application context [springUrl=" + cfgUrl + ", err=" + e.getMessage() + ']', e); } }
Example 3
Source File: IgniteSpringHelperImpl.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public <T> IgniteBiTuple<Collection<T>, ? extends GridSpringResourceContext> loadConfigurations( InputStream cfgStream, Class<T> cls, String... excludedProps) throws IgniteCheckedException { ApplicationContext springCtx = applicationContext(cfgStream, excludedProps); Map<String, T> cfgMap; try { cfgMap = springCtx.getBeansOfType(cls); } catch (BeansException e) { throw new IgniteCheckedException("Failed to instantiate bean [type=" + cls + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null || cfgMap.isEmpty()) throw new IgniteCheckedException("Failed to find configuration in: " + cfgStream); return F.t(cfgMap.values(), new GridSpringResourceContextImpl(springCtx)); }
Example 4
Source File: IgniteSpringHelperImpl.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public <T> IgniteBiTuple<Collection<T>, ? extends GridSpringResourceContext> loadConfigurations(URL cfgUrl, Class<T> cls, String... excludedProps) throws IgniteCheckedException { ApplicationContext springCtx = applicationContext(cfgUrl, excludedProps); Map<String, T> cfgMap; try { cfgMap = springCtx.getBeansOfType(cls); } catch (BeansException e) { throw new IgniteCheckedException("Failed to instantiate bean [type=" + cls + ", err=" + e.getMessage() + ']', e); } if (cfgMap == null || cfgMap.isEmpty()) throw new IgniteCheckedException("Failed to find configuration in: " + cfgUrl); return F.t(cfgMap.values(), new GridSpringResourceContextImpl(springCtx)); }
Example 5
Source File: JVoiceXmlConfiguration.java From JVoiceXML with GNU Lesser General Public License v2.1 | 6 votes |
/** * {@inheritDoc} */ @Override public synchronized <T extends Object> T loadObject( final Class<T> baseClass, final String key) throws ConfigurationException { if (context == null) { LOGGER.warn("configuration error. unable to load object: key '" + key + "' from a null configuration"); return null; } if (!context.containsBean(key)) { LOGGER.warn("unable to load object: key '" + key + "' not found"); return null; } final Object object; try { if (LOGGER.isDebugEnabled()) { LOGGER.debug("loading bean with id '" + key + "'"); } object = context.getBean(key, baseClass); } catch (BeansException e) { throw new ConfigurationException(e.getMessage(), e); } return baseClass.cast(object); }
Example 6
Source File: ServiceLocatorFactoryBean.java From java-technology-stack with MIT License | 5 votes |
/** * Create a service locator exception for the given cause. * Only called in case of a custom service locator exception. * <p>The default implementation can handle all variations of * message and exception arguments. * @param exceptionConstructor the constructor to use * @param cause the cause of the service lookup failure * @return the service locator exception to throw * @see #setServiceLocatorExceptionClass */ protected Exception createServiceLocatorException(Constructor<Exception> exceptionConstructor, BeansException cause) { Class<?>[] paramTypes = exceptionConstructor.getParameterTypes(); Object[] args = new Object[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { if (String.class == paramTypes[i]) { args[i] = cause.getMessage(); } else if (paramTypes[i].isInstance(cause)) { args[i] = cause; } } return BeanUtils.instantiateClass(exceptionConstructor, args); }
Example 7
Source File: DefaultWagonFactory.java From archiva with Apache License 2.0 | 5 votes |
@Override public Wagon getWagon( WagonFactoryRequest wagonFactoryRequest ) throws WagonFactoryException { try { String protocol = StringUtils.startsWith( wagonFactoryRequest.getProtocol(), "wagon#" ) ? wagonFactoryRequest.getProtocol() : "wagon#" + wagonFactoryRequest.getProtocol(); // if it's a ntlm proxy we have to lookup the wagon light which support thats // wagon http client doesn't support that if ( wagonFactoryRequest.getNetworkProxy() != null && wagonFactoryRequest.getNetworkProxy().isUseNtlm() ) { protocol = protocol + "-ntlm"; } Wagon wagon = applicationContext.getBean( protocol, Wagon.class ); wagon.addTransferListener( debugTransferListener ); configureUserAgent( wagon, wagonFactoryRequest ); return wagon; } catch ( BeansException e ) { throw new WagonFactoryException( e.getMessage(), e ); } }
Example 8
Source File: GridFactorySelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Gets Spring application context by given path. * * @param path Spring application context configuration path. * @return Spring application context. * @throws IgniteCheckedException If given path or xml-configuration at this path is invalid. */ private GenericApplicationContext getSpringContext(String path) throws IgniteCheckedException { try { GenericApplicationContext ctx = new GenericApplicationContext(); new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(new UrlResource(U.resolveIgniteUrl(path))); ctx.refresh(); return ctx; } catch (BeansException e) { throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e); } }
Example 9
Source File: UserDetailsServiceTest.java From timely with Apache License 2.0 | 5 votes |
@BeforeClass public static void setupClass() { try { springContext = new ClassPathXmlApplicationContext("security.xml"); userDetailsService = (UserDetailsService) springContext.getBean("timelyUserDetailsService"); } catch (BeansException e) { throw new ServiceConfigurationError("Error initializing from spring: " + e.getMessage(), e.getRootCause()); } }
Example 10
Source File: ServiceLocatorFactoryBean.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Create a service locator exception for the given cause. * Only called in case of a custom service locator exception. * <p>The default implementation can handle all variations of * message and exception arguments. * @param exceptionConstructor the constructor to use * @param cause the cause of the service lookup failure * @return the service locator exception to throw * @see #setServiceLocatorExceptionClass */ protected Exception createServiceLocatorException(Constructor<Exception> exceptionConstructor, BeansException cause) { Class<?>[] paramTypes = exceptionConstructor.getParameterTypes(); Object[] args = new Object[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { if (String.class == paramTypes[i]) { args[i] = cause.getMessage(); } else if (paramTypes[i].isInstance(cause)) { args[i] = cause; } } return BeanUtils.instantiateClass(exceptionConstructor, args); }
Example 11
Source File: GenericFilterBean.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Standard way of initializing this filter. * Map config parameters onto bean properties of this filter, and * invoke subclass initialization. * @param filterConfig the configuration for this filter * @throws ServletException if bean properties are invalid (or required * properties are missing), or if subclass initialization fails. * @see #initFilterBean */ @Override public final void init(FilterConfig filterConfig) throws ServletException { Assert.notNull(filterConfig, "FilterConfig must not be null"); if (logger.isDebugEnabled()) { logger.debug("Initializing filter '" + filterConfig.getFilterName() + "'"); } this.filterConfig = filterConfig; // Set bean properties from init parameters. try { PropertyValues pvs = new FilterConfigPropertyValues(filterConfig, this.requiredProperties); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new ServletContextResourceLoader(filterConfig.getServletContext()); bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, this.environment)); initBeanWrapper(bw); bw.setPropertyValues(pvs, true); } catch (BeansException ex) { String msg = "Failed to set bean properties on filter '" + filterConfig.getFilterName() + "': " + ex.getMessage(); logger.error(msg, ex); throw new NestedServletException(msg, ex); } // Let subclasses do whatever initialization they like. initFilterBean(); if (logger.isDebugEnabled()) { logger.debug("Filter '" + filterConfig.getFilterName() + "' configured successfully"); } }
Example 12
Source File: ServiceLocatorFactoryBean.java From blog_demos with Apache License 2.0 | 5 votes |
/** * Create a service locator exception for the given cause. * Only called in case of a custom service locator exception. * <p>The default implementation can handle all variations of * message and exception arguments. * @param exceptionConstructor the constructor to use * @param cause the cause of the service lookup failure * @return the service locator exception to throw * @see #setServiceLocatorExceptionClass */ protected Exception createServiceLocatorException(Constructor<Exception> exceptionConstructor, BeansException cause) { Class<?>[] paramTypes = exceptionConstructor.getParameterTypes(); Object[] args = new Object[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { if (paramTypes[i].equals(String.class)) { args[i] = cause.getMessage(); } else if (paramTypes[i].isInstance(cause)) { args[i] = cause; } } return BeanUtils.instantiateClass(exceptionConstructor, args); }
Example 13
Source File: ServiceLocatorFactoryBean.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Create a service locator exception for the given cause. * Only called in case of a custom service locator exception. * <p>The default implementation can handle all variations of * message and exception arguments. * @param exceptionConstructor the constructor to use * @param cause the cause of the service lookup failure * @return the service locator exception to throw * @see #setServiceLocatorExceptionClass */ protected Exception createServiceLocatorException(Constructor<Exception> exceptionConstructor, BeansException cause) { Class<?>[] paramTypes = exceptionConstructor.getParameterTypes(); Object[] args = new Object[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { if (String.class == paramTypes[i]) { args[i] = cause.getMessage(); } else if (paramTypes[i].isInstance(cause)) { args[i] = cause; } } return BeanUtils.instantiateClass(exceptionConstructor, args); }
Example 14
Source File: ServiceLocatorFactoryBean.java From spring-analysis-note with MIT License | 5 votes |
/** * Create a service locator exception for the given cause. * Only called in case of a custom service locator exception. * <p>The default implementation can handle all variations of * message and exception arguments. * @param exceptionConstructor the constructor to use * @param cause the cause of the service lookup failure * @return the service locator exception to throw * @see #setServiceLocatorExceptionClass */ protected Exception createServiceLocatorException(Constructor<Exception> exceptionConstructor, BeansException cause) { Class<?>[] paramTypes = exceptionConstructor.getParameterTypes(); Object[] args = new Object[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { if (String.class == paramTypes[i]) { args[i] = cause.getMessage(); } else if (paramTypes[i].isInstance(cause)) { args[i] = cause; } } return BeanUtils.instantiateClass(exceptionConstructor, args); }
Example 15
Source File: UnsatisfiedDependencyException.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Create a new UnsatisfiedDependencyException. * @param resourceDescription description of the resource that the bean definition came from * @param beanName the name of the bean requested * @param propertyName the name of the bean property that couldn't be satisfied * @param ex the bean creation exception that indicated the unsatisfied dependency */ public UnsatisfiedDependencyException( String resourceDescription, String beanName, String propertyName, BeansException ex) { this(resourceDescription, beanName, propertyName, (ex != null ? ": " + ex.getMessage() : "")); initCause(ex); }
Example 16
Source File: UnsatisfiedDependencyException.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Create a new UnsatisfiedDependencyException. * @param resourceDescription description of the resource that the bean definition came from * @param beanName the name of the bean requested * @param ctorArgIndex the index of the constructor argument that couldn't be satisfied * @param ctorArgType the type of the constructor argument that couldn't be satisfied * @param ex the bean creation exception that indicated the unsatisfied dependency */ public UnsatisfiedDependencyException( String resourceDescription, String beanName, int ctorArgIndex, Class<?> ctorArgType, BeansException ex) { this(resourceDescription, beanName, ctorArgIndex, ctorArgType, (ex != null ? ": " + ex.getMessage() : "")); initCause(ex); }
Example 17
Source File: UnsatisfiedDependencyException.java From blog_demos with Apache License 2.0 | 3 votes |
/** * Create a new UnsatisfiedDependencyException. * @param resourceDescription description of the resource that the bean definition came from * @param beanName the name of the bean requested * @param ctorArgIndex the index of the constructor argument that couldn't be satisfied * @param ctorArgType the type of the constructor argument that couldn't be satisfied * @param ex the bean creation exception that indicated the unsatisfied dependency */ public UnsatisfiedDependencyException( String resourceDescription, String beanName, int ctorArgIndex, Class<?> ctorArgType, BeansException ex) { this(resourceDescription, beanName, ctorArgIndex, ctorArgType, (ex != null ? ": " + ex.getMessage() : "")); initCause(ex); }
Example 18
Source File: UnsatisfiedDependencyException.java From blog_demos with Apache License 2.0 | 3 votes |
/** * Create a new UnsatisfiedDependencyException. * @param resourceDescription description of the resource that the bean definition came from * @param beanName the name of the bean requested * @param propertyName the name of the bean property that couldn't be satisfied * @param ex the bean creation exception that indicated the unsatisfied dependency */ public UnsatisfiedDependencyException( String resourceDescription, String beanName, String propertyName, BeansException ex) { this(resourceDescription, beanName, propertyName, (ex != null ? ": " + ex.getMessage() : "")); initCause(ex); }
Example 19
Source File: UnsatisfiedDependencyException.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Create a new UnsatisfiedDependencyException. * @param resourceDescription description of the resource that the bean definition came from * @param beanName the name of the bean requested * @param ctorArgIndex the index of the constructor argument that couldn't be satisfied * @param ctorArgType the type of the constructor argument that couldn't be satisfied * @param ex the bean creation exception that indicated the unsatisfied dependency * @deprecated in favor of {@link #UnsatisfiedDependencyException(String, String, InjectionPoint, BeansException)} */ @Deprecated public UnsatisfiedDependencyException( String resourceDescription, String beanName, int ctorArgIndex, Class<?> ctorArgType, BeansException ex) { this(resourceDescription, beanName, ctorArgIndex, ctorArgType, (ex != null ? ex.getMessage() : "")); initCause(ex); }