use of org.springframework.beans.BeansException in project spring-framework by spring-projects.
the class PropertyComparator method getPropertyValue.
/**
* Get the SortDefinition's property value for the given object.
* @param obj the object to get the property value for
* @return the property value
*/
@Nullable
private Object getPropertyValue(Object obj) {
// first place, let the exception through.
try {
BeanWrapperImpl beanWrapper = new BeanWrapperImpl(false);
beanWrapper.setWrappedInstance(obj);
return beanWrapper.getPropertyValue(this.sortDefinition.getProperty());
} catch (BeansException ex) {
logger.debug("PropertyComparator could not access property - treating as null for sorting", ex);
return null;
}
}
use of org.springframework.beans.BeansException in project ignite by apache.
the class GridSingleExecutionTest method getConfigurations.
/**
* Initializes configurations.
*
* @param springCfgPath Configuration file path.
* @param log Log file name.
* @return List of configurations.
* @throws IgniteCheckedException If failed..
*/
private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath, String log) throws IgniteCheckedException {
File path = GridTestUtils.resolveIgnitePath(springCfgPath);
if (path == null) {
throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
}
if (!path.isFile())
throw new IgniteCheckedException("Provided file path is not a file: " + path);
// Add no-op logger to remove no-appender warning.
Appender app = new NullAppender();
Logger.getRootLogger().addAppender(app);
ApplicationContext springCtx;
try {
springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
} catch (BeansException | MalformedURLException e) {
throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
}
Map cfgMap;
try {
// Note: Spring is not generics-friendly.
cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
} catch (BeansException e) {
throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null)
throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
// Remove previously added no-op logger.
Logger.getRootLogger().removeAppender(app);
if (cfgMap.isEmpty())
throw new IgniteCheckedException("Can't find grid factory configuration in: " + path);
Collection<IgniteConfiguration> res = new ArrayList<>();
for (IgniteConfiguration cfg : (Collection<IgniteConfiguration>) cfgMap.values()) {
UUID nodeId = UUID.randomUUID();
cfg.setNodeId(nodeId);
cfg.setGridLogger(initLogger(log));
res.add(cfg);
}
return res;
}
use of org.springframework.beans.BeansException in project ignite by apache.
the class GridAbstractTest method loadConfiguration.
/**
* Loads configuration from the given Spring XML file.
*
* @param springCfgPath Path to file.
* @return Grid configuration.
* @throws IgniteCheckedException If load failed.
*/
@SuppressWarnings("deprecation")
protected IgniteConfiguration loadConfiguration(String springCfgPath) throws IgniteCheckedException {
URL cfgLocation = U.resolveIgniteUrl(springCfgPath);
if (cfgLocation == null)
cfgLocation = U.resolveIgniteUrl(springCfgPath, false);
assert cfgLocation != null;
ApplicationContext springCtx;
try {
springCtx = new FileSystemXmlApplicationContext(cfgLocation.toString());
} catch (BeansException e) {
throw new IgniteCheckedException("Failed to instantiate Spring XML application context.", e);
}
Map cfgMap;
try {
// Note: Spring is not generics-friendly.
cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
} catch (BeansException e) {
throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null)
throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + springCfgPath);
if (cfgMap.isEmpty())
throw new IgniteCheckedException("Can't find grid factory configuration in: " + springCfgPath);
else if (cfgMap.size() > 1)
throw new IgniteCheckedException("More than one configuration provided for cache load test: " + cfgMap.values());
IgniteConfiguration cfg = (IgniteConfiguration) cfgMap.values().iterator().next();
cfg.setNodeId(UUID.randomUUID());
return cfg;
}
use of org.springframework.beans.BeansException in project ignite by apache.
the class IgniteSpringHelperImpl method loadConfigurations.
/**
* {@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));
}
use of org.springframework.beans.BeansException in project ignite by apache.
the class IgniteSpringHelperImpl method loadConfigurations.
/**
* {@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));
}
Aggregations