use of org.springframework.beans.factory.BeanInitializationException in project com.revolsys.open by revolsys.
the class DatabaseConfigurer method postProcessBeanFactory.
/**
* @param beanFactory The bean factory the bean is loaded from.
*/
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) {
final Map<String, String> properties = new HashMap<>();
Connection connection = null;
try {
connection = JdbcUtils.getConnection(this.dataSource);
final String sql = "SELECT " + this.keyColumnName + ", " + this.valueColumnName + " FROM " + this.tableName;
final Statement statement = connection.createStatement();
final ResultSet results = statement.executeQuery(sql);
while (results.next()) {
final String key = results.getString(1);
final String value = results.getString(2);
properties.put(key, value);
}
} catch (final SQLException e) {
throw new BeanInitializationException(e.getMessage(), e);
} finally {
JdbcUtils.release(connection, this.dataSource);
}
processProperties(beanFactory, properties);
}
use of org.springframework.beans.factory.BeanInitializationException in project com.revolsys.open by revolsys.
the class DatabasePropertyOverrideConfigurer method applyMapPropertyValue.
/**
* Apply the given property value to the corresponding map property on the
* bean.
*
* @param factory The bean factory.
* @param beanName The name of the bean.
* @param propertyName The name of the property.
* @param mapKey The key in the map to set.
* @param value The value to set.
*/
protected void applyMapPropertyValue(final ConfigurableListableBeanFactory factory, final String beanName, final String propertyName, final String mapKey, final String value) {
this.beanNames.add(beanName);
final BeanDefinition bd = factory.getBeanDefinition(beanName);
final MutablePropertyValues values = bd.getPropertyValues();
final PropertyValue propertyValue = values.getPropertyValue(propertyName);
if (propertyValue != null) {
final Object objectValue = propertyValue.getValue();
if (objectValue instanceof Map) {
final Map map = (Map) objectValue;
map.put(mapKey, value);
} else {
throw new BeanInitializationException("Bean property [" + beanName + "." + propertyName + "] is not a Map");
}
} else {
final Map<String, Object> map = new HashMap<>();
map.put(mapKey, value);
values.addPropertyValue(propertyName, map);
}
}
use of org.springframework.beans.factory.BeanInitializationException in project OpenOLAT by OpenOLAT.
the class WebappHelper method testUtf8FileSystem.
/**
* Test if filesystem is capable to store UTF-8 characters
* Try to read/write a file with UTF-8 chars in the filename in a temporary directory.
*/
private void testUtf8FileSystem() {
File tmpDir = new File(new File(WebappHelper.getUserDataRoot()), "tmp");
if (!tmpDir.exists())
tmpDir.mkdir();
File writeFile = new File(tmpDir, "UTF-8 test läsÖiç-首页|新");
if (writeFile.exists()) {
// remove exising files first
writeFile.delete();
}
try {
writeFile.createNewFile();
} catch (IOException e) {
log.warn("No UTF-8 capable filesystem found! Error while writing testfile to filesystem", e);
}
// try to lookup file: get files from filesystem and search for file we created above
File[] tmpFiles = tmpDir.listFiles();
boolean foundUtf8File = false;
if (tmpFiles != null) {
for (int i = 0; i < tmpFiles.length; i++) {
File tmpFile = tmpFiles[i];
if (tmpFile.getName().equals("UTF-8 test läsÖiç-首页|新")) {
foundUtf8File = true;
break;
}
}
}
if (foundUtf8File) {
// test ok
log.info("UTF-8 capable filesystem detected");
} else {
// test failed
log.warn("No UTF-8 capable filesystem found! Could not read / write UTF-8 characters from / to filesystem! " + "You probably misconfigured your system, try setting your LANG variable to a correct value.");
log.warn("Your current file encoding configuration: java.nio.charset.Charset.defaultCharset().name()::" + java.nio.charset.Charset.defaultCharset().name() + " (the one used) and your system property file.encoding::" + System.getProperty("file.encoding") + " (the one configured)");
}
// try to delete file anyway
writeFile.delete();
if (!foundUtf8File && WebappHelper.enforceUtf8Filesystem) {
throw new BeanInitializationException("System startup aborted to to file system missconfiguration. See previous warnings in logfile and fix your " + "Java environment. This check can be disabled by setting enforce.utf8.filesystem=false, but be aware that the " + "decision to use a certain encoding on the filesystem is a one-time decision. You can not cange to UTF-8 later!");
}
}
use of org.springframework.beans.factory.BeanInitializationException in project qpp-conversion-tool by CMSgov.
the class DynamoDbConfig method dynamoDbMapper.
/**
* Creates a DynamoDB object mapper {@link Bean} that interacts with {@link DynamoDBTable} annotated POJOs.
* Based on an available {@link AmazonDynamoDB} and {@link AWSKMS} {@link Bean}.
*
* Creates a DynamoDB object that depends on two different environment variables. {@code DYNAMO_TABLE_NAME} and
* {@code KMS_KEY}.
*
* If {@code DYNAMO_TABLE_NAME} is specified, the value will be used for all read/write from/to the table of that name
* regardless of what is specified for {@link DynamoDBTable}. Else, the table specified for {@link DynamoDBTable} will be
* used like normal.
*
* If {@code KMS_KEY} is specified, items in the tables will be encrypted. Else, the items will not be encrypted.
*
* @param dynamoDbClient The {@link AmazonDynamoDB} {@link Bean}.
* @return The DynamoDB object mapper
*/
@Bean
public DynamoDBMapper dynamoDbMapper(AmazonDynamoDB dynamoDbClient) {
DynamoDBMapper dynamoDbMapper;
final Optional<String> kmsKey = getOptionalProperty(Constants.KMS_KEY_ENV_VARIABLE);
final Optional<String> tableName = getOptionalProperty(Constants.DYNAMO_TABLE_NAME_ENV_VARIABLE);
final Optional<String> noAudit = getOptionalProperty(Constants.NO_AUDIT_ENV_VARIABLE);
if (!noAudit.isPresent()) {
if (tableName.isPresent() && kmsKey.isPresent()) {
API_LOG.info("Using DynamoDB table name {} and KMS key {}.", tableName, kmsKey);
dynamoDbMapper = createDynamoDbMapper(dynamoDbClient, tableNameOverrideConfig(tableName.get()), encryptionTransformer(kmsKey.get()));
} else if (kmsKey.isPresent()) {
API_LOG.warn("Using KMS key {}, but no DynamoDB table name specified.", tableName);
dynamoDbMapper = createDynamoDbMapper(dynamoDbClient, getDynamoDbMapperConfig(), encryptionTransformer(kmsKey.get()));
} else {
API_LOG.error(NO_KMS_KEY + " This is a fatal error.");
throw new BeanInitializationException(NO_KMS_KEY);
}
} else {
API_LOG.info("Will not save any audit information.");
dynamoDbMapper = null;
}
return dynamoDbMapper;
}
use of org.springframework.beans.factory.BeanInitializationException in project spring-framework by spring-projects.
the class ViewResolverRegistry method scriptTemplate.
/**
* Register a script template view resolver with an empty default view name prefix and suffix.
* <p><strong>Note</strong> that you must also configure script templating by
* adding a {@link ScriptTemplateConfigurer} bean.
* @since 5.0.4
*/
public UrlBasedViewResolverRegistration scriptTemplate() {
if (!checkBeanOfType(ScriptTemplateConfigurer.class)) {
throw new BeanInitializationException("In addition to a script template view resolver " + "there must also be a single ScriptTemplateConfig bean in this web application context " + "(or its parent): ScriptTemplateConfigurer is the usual implementation. " + "This bean may be given any name.");
}
ScriptRegistration registration = new ScriptRegistration();
UrlBasedViewResolver resolver = registration.getViewResolver();
if (this.applicationContext != null) {
resolver.setApplicationContext(this.applicationContext);
}
this.viewResolvers.add(resolver);
return registration;
}
Aggregations