Commit 1eb917bf authored by Matija Obreza's avatar Matija Obreza
Browse files

“config.file” environment variable for specifying a .properties file external to the classloader

parent 7ba96281
...@@ -18,7 +18,6 @@ package org.genesys2.spring.config; ...@@ -18,7 +18,6 @@ package org.genesys2.spring.config;
import javax.persistence.Entity; import javax.persistence.Entity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.genesys2.spring.validation.oval.spring.SpringOvalValidator; import org.genesys2.spring.validation.oval.spring.SpringOvalValidator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
......
...@@ -16,20 +16,28 @@ ...@@ -16,20 +16,28 @@
package org.genesys2.spring.config; package org.genesys2.spring.config;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@Configuration @Configuration
public class SpringProperties { public class SpringProperties {
@Value("${config.file}")
private String extraConfigFile;
@Bean @Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
final PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer(); final PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
// Need to ignore "genesys.properties" if not found // Need to ignore "genesys.properties" if not found
...@@ -37,15 +45,21 @@ public class SpringProperties { ...@@ -37,15 +45,21 @@ public class SpringProperties {
propertyPlaceholderConfigurer.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE); propertyPlaceholderConfigurer.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
propertyPlaceholderConfigurer.setFileEncoding("utf-8"); propertyPlaceholderConfigurer.setFileEncoding("utf-8");
propertyPlaceholderConfigurer.setLocations(new Resource[] { List<Resource> locations = new ArrayList<>();
new ClassPathResource("application.properties"), locations.add(new ClassPathResource("application.properties"));
new ClassPathResource("spring/spring.properties"), locations.add(new ClassPathResource("spring/spring.properties"));
// Include genesys.properties // Include genesys.properties
new ClassPathResource("genesys.properties") }); locations.add(new ClassPathResource("genesys.properties"));
return propertyPlaceholderConfigurer; if (StringUtils.isNotBlank(extraConfigFile)) {
System.err.println("Registering extra filesystem resource at " + extraConfigFile);
locations.add(new FileSystemResource(extraConfigFile));
} }
propertyPlaceholderConfigurer.setLocations(locations.toArray(new Resource[] {}));
return propertyPlaceholderConfigurer;
}
/** /**
* localeURLFilter in web.xml: en es de fr fa ar ru zh pt * localeURLFilter in web.xml: en es de fr fa ar ru zh pt
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment