下面列出了org.springframework.beans.BeansException#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* {@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);
}
/** {@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));
}
/** {@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));
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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");
}
}
/**
* 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);
}
@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());
}
}
/**
* 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);
}
}
@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 );
}
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}