List of usage examples for org.springframework.beans.factory.config PropertiesFactoryBean setLocations
public void setLocations(Resource... locations)
From source file:com.logsniffer.app.CoreAppConfig.java
@Bean(name = { BEAN_LOGSNIFFER_PROPS }) @Autowired/*from ww w . j av a2 s .co m*/ public PropertiesFactoryBean logSnifferProperties(final ApplicationContext ctx) throws IOException { if (ctx.getEnvironment().acceptsProfiles("!" + ContextProvider.PROFILE_NONE_QA)) { final File qaFile = File.createTempFile("logsniffer", "qa"); qaFile.delete(); final String qaHomeDir = qaFile.getPath(); logger.info("QA mode active, setting random home directory: {}", qaHomeDir); System.setProperty("logsniffer.home", qaHomeDir); } final PathMatchingResourcePatternResolver pathMatcher = new PathMatchingResourcePatternResolver(); Resource[] classPathProperties = pathMatcher.getResources("classpath*:/config/**/logsniffer-*.properties"); final Resource[] metainfProperties = pathMatcher .getResources("classpath*:/META-INF/**/logsniffer-*.properties"); final PropertiesFactoryBean p = new PropertiesFactoryBean(); for (final Resource r : metainfProperties) { classPathProperties = (Resource[]) ArrayUtils.add(classPathProperties, r); } classPathProperties = (Resource[]) ArrayUtils.add(classPathProperties, new FileSystemResource(System.getProperty("logsniffer.home") + "/" + LOGSNIFFER_PROPERTIES_FILE)); p.setLocations(classPathProperties); p.setProperties(System.getProperties()); p.setLocalOverride(true); p.setIgnoreResourceNotFound(true); return p; }
From source file:org.jahia.test.framework.JahiaWebInitializer.java
@Override public void initialize(GenericWebApplicationContext webAppContext) { try {/* w w w. j av a 2s. c o m*/ Resource[] resources = webAppContext .getResources("classpath*:org/jahia/config/jahiaunittest.properties"); PropertiesFactoryBean propertiesFactory = new PropertiesFactoryBean(); propertiesFactory.setLocations(resources); propertiesFactory.afterPropertiesSet(); Properties properties = propertiesFactory.getObject(); String jackrabbitHome = (String) properties.get("jahia.jackrabbit.home"); if (jackrabbitHome != null) { jackrabbitHome = webAppContext.getResource(jackrabbitHome).getURL().getPath(); File repoHome = new File(jackrabbitHome); if (!repoHome.exists()) { repoHome.mkdirs(); } if (resources[0] != null && ResourceUtils.isJarURL(resources[0].getURL())) { URL jarUrl = ResourceUtils.extractJarFileURL(resources[0].getURL()); try { new JahiaArchiveFileHandler(jarUrl.getPath()).unzip("./target/test-repo", new PathFilter() { @Override public boolean accept(String path) { // TODO Auto-generated method stub return path.startsWith("WEB-INF"); } }); } catch (JahiaException e) { logger.error("Unable to extract JAR"); } } else if (resources[0] != null) { FileUtils.copyDirectory( new File(StringUtils.substringBefore(resources[0].getURI().getPath(), "org"), "WEB-INF"), new File("./target/test-repo", "WEB-INF")); } } } catch (IOException e) { } }