use of org.springframework.beans.factory.BeanInitializationException in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurer method postProcessBeanFactory.
/**
* {@inheritDoc}
* <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
* against this configurer's set of {@link PropertySources}, which includes:
* <ul>
* <li>all {@linkplain org.springframework.core.env.ConfigurableEnvironment#getPropertySources
* environment property sources}, if an {@code Environment} {@linkplain #setEnvironment is present}
* <li>{@linkplain #mergeProperties merged local properties}, if {@linkplain #setLocation any}
* {@linkplain #setLocations have} {@linkplain #setProperties been}
* {@linkplain #setPropertiesArray specified}
* <li>any property sources set by calling {@link #setPropertySources}
* </ul>
* <p>If {@link #setPropertySources} is called, <strong>environment and local properties will be
* ignored</strong>. This method is designed to give the user fine-grained control over property
* sources, and once set, the configurer makes no assumptions about adding additional sources.
*/
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (this.propertySources == null) {
this.propertySources = new MutablePropertySources();
if (this.environment != null) {
this.propertySources.addLast(new PropertySource<Environment>(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
@Override
public String getProperty(String key) {
return this.source.getProperty(key);
}
});
}
try {
PropertySource<?> localPropertySource = new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, mergeProperties());
if (this.localOverride) {
this.propertySources.addFirst(localPropertySource);
} else {
this.propertySources.addLast(localPropertySource);
}
} catch (IOException ex) {
throw new BeanInitializationException("Could not load properties", ex);
}
}
processProperties(beanFactory, new PropertySourcesPropertyResolver(this.propertySources));
this.appliedPropertySources = this.propertySources;
}
use of org.springframework.beans.factory.BeanInitializationException in project OpenClinica by OpenClinica.
the class QueryStore method resolveDbFolder.
protected String resolveDbFolder() {
try {
Connection conn = dataSource.getConnection();
CoreResources.setSchema(conn);
String url = conn.getMetaData().getURL();
if (url.startsWith("jdbc:postgresql")) {
return "postgres";
}
if (url.startsWith("jdbc:oracle")) {
return "oracle";
}
throw new BeanInitializationException("Unrecognized JDBC url " + url);
} catch (SQLException e) {
throw new BeanInitializationException("Unable to read datasource information", e);
}
}
use of org.springframework.beans.factory.BeanInitializationException in project FredaBlog by yangjinlong86.
the class EncryptPropertyPlaceholderConfigurer method processProperties.
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {
try {
String username = props.getProperty("username");
if (StringUtils.isNotBlank(username)) {
props.setProperty("username", EncryptUtil.decode(username));
}
String password = props.getProperty("password");
if (StringUtils.isNotBlank(password)) {
props.setProperty("password", EncryptUtil.decode(password));
}
super.processProperties(beanFactory, props);
} catch (Exception e) {
logger.error("encrypt error!", e);
throw new BeanInitializationException(e.getMessage());
}
}
use of org.springframework.beans.factory.BeanInitializationException in project com.revolsys.open by revolsys.
the class BeanConfigurrer method processOverride.
/**
* Process the given key as 'beanName.property' entry.
*/
protected void processOverride(final ConfigurableListableBeanFactory factory, final String key, Object value) {
try {
if (value instanceof BeanReference) {
final BeanReference reference = (BeanReference) value;
value = reference.getBean();
}
final Matcher matcher = BeanConfigurrer.KEY_PATTERN.matcher(key);
if (matcher.matches()) {
final String beanName = matcher.group(1);
final String mapKey = matcher.group(2);
final String propertyName = matcher.group(3);
if (mapKey == null) {
if (propertyName == null) {
if (factory.containsBean(beanName)) {
BeanDefinition beanDefinition = factory.getBeanDefinition(beanName);
try {
final ClassLoader classLoader = this.applicationContext.getClassLoader();
final String beanClassName = beanDefinition.getBeanClassName();
final Class<?> beanClass = Class.forName(beanClassName, true, classLoader);
if (Parameter.class.isAssignableFrom(beanClass)) {
while (beanDefinition.getOriginatingBeanDefinition() != null) {
beanDefinition = beanDefinition.getOriginatingBeanDefinition();
}
final MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
PropertyValue propertyValue = new PropertyValue("value", value);
final PropertyValue typeValue = propertyValues.getPropertyValue("type");
if (typeValue != null) {
try {
final Class<?> typeClass;
final Object typeValueObject = typeValue.getValue();
if (typeValueObject instanceof Class<?>) {
typeClass = (Class<?>) typeValueObject;
} else {
final String typeClassName = typeValueObject.toString();
typeClass = Class.forName(typeClassName, true, classLoader);
}
final Object convertedValue = new SimpleTypeConverter().convertIfNecessary(value, typeClass);
propertyValue = new PropertyValue("value", convertedValue);
} catch (final Throwable e) {
Logs.error(this, "Unable to set " + beanName + ".value=" + value, e);
}
}
propertyValues.addPropertyValue(propertyValue);
}
} catch (final ClassNotFoundException e) {
Logs.error(this, "Unable to set " + beanName + ".value=" + value, e);
}
} else if (value != null) {
newParameterBeanDefinition(factory, beanName, value);
}
} else {
setAttributeValue(factory, beanName, propertyName, value);
Logs.debug(this, "Property '" + key + "' set to value [" + value + "]");
}
} else if (propertyName == null) {
setMapValue(factory, key, beanName, mapKey, value);
} else {
Logs.error(this, "Invalid syntax unable to set " + key + "=" + value);
}
}
} catch (final BeansException ex) {
final String msg = "Could not process key '" + key + "' in PropertyOverrideConfigurer";
if (!this.ignoreInvalidKeys) {
throw new BeanInitializationException(msg, ex);
}
Logs.debug(this, msg, ex);
}
}
use of org.springframework.beans.factory.BeanInitializationException in project com.revolsys.open by revolsys.
the class DatabasePropertyOverrideConfigurer method processKey.
/**
* Process the given key as 'beanName.property' entry.
*
* @param factory The bean factory.
* @param key The key used to set the property.
* @param value The value to set. @ If there was an problem setting the value.
*/
protected void processKey(final ConfigurableListableBeanFactory factory, final String key, final String value) {
final Matcher mapProperetyValueMatcher = MAP_PROPERTY_VALUE_PATTERN.matcher(key);
if (mapProperetyValueMatcher.matches()) {
final String beanName = mapProperetyValueMatcher.group(1);
final String beanProperty = mapProperetyValueMatcher.group(2);
final String mapKey = mapProperetyValueMatcher.group(3);
applyMapPropertyValue(factory, beanName, beanProperty, mapKey, value);
} else {
final Matcher simpleMatcher = SIMPLE_PROPERTY_PATTERN.matcher(key);
if (simpleMatcher.matches()) {
final String beanName = simpleMatcher.group(1);
final String beanProperty = simpleMatcher.group(2);
applyPropertyValue(factory, beanName, beanProperty, value);
} else {
throw new BeanInitializationException("Invalid key [" + key + "]");
}
}
if (getLog().isDebugEnabled()) {
getLog().debug("WebProperty '" + key + "' set to [" + value + "]");
}
}
Aggregations