List of usage examples for org.springframework.core.io.support ResourcePropertySource ResourcePropertySource
public ResourcePropertySource(String location) throws IOException
From source file:com.pavikumbhar.javaheart.springconfiguration.ContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); System.out.println("com.pavikumbhar.javaheart.ContextInitializer.initialize()"); try {/*from ww w. j a v a2 s. c om*/ environment.getPropertySources().addFirst(new ResourcePropertySource("classpath:env.properties")); String profile = environment.getProperty("spring.profiles.active"); environment.setActiveProfiles(profile); System.err.println(" spring.profiles.active profile :" + profile); System.err.println("env.properties loaded :" + ContextInitializer.class.getName()); } catch (IOException e) { // it's ok if the file is not there. we will just log that info. System.out.println( "didn't find env.properties in classpath so not loading it in the AppContextInitialized"); } }
From source file:com.bbytes.jfilesync.JFileSyncClient.java
public JFileSyncClient() { this.context = new ClassPathXmlApplicationContext(new String[] { "classpath:spring/jfilesync-client.xml" }, false);/*w ww . j a va2s. c o m*/ try { context.getEnvironment().getPropertySources() .addFirst(new ResourcePropertySource("classpath:jfilesync-client.properties")); } catch (IOException e) { log.error(e.getMessage(), e); } this.context.refresh(); fileSyncChannel = context.getBean(JChannel.class); ftpClientFactory = context.getBean(FTPClientFactory.class); destinationFolder = (String) context.getBean("destinationFolder"); fileSyncListenerThread = new JFileSyncListenerClientThread(fileSyncChannel); fileSyncListenerThread.setDestinationFolder(destinationFolder); fileSyncListenerThread.setFtpClientFactory(ftpClientFactory); }
From source file:io.lavagna.common.LavagnaEnvironment.java
public LavagnaEnvironment(ConfigurableEnvironment environment) { this.environment = environment; if (environment.containsProperty(LAVAGNA_CONFIG_LOCATION) && StringUtils.isNotBlank(environment.getProperty(LAVAGNA_CONFIG_LOCATION))) { String configLocation = environment.getProperty(LAVAGNA_CONFIG_LOCATION); LOG.info("Detected config file {}, loading it", configLocation); try {//from w ww .ja v a 2 s. c o m environment.getPropertySources() .addFirst(new ResourcePropertySource(new UrlResource(configLocation))); } catch (IOException ioe) { throw new IllegalStateException( "error while loading external configuration file at " + configLocation, ioe); } } setSystemPropertyIfNull(environment, "datasource.dialect", "HSQLDB"); setSystemPropertyIfNull(environment, "datasource.url", "jdbc:hsqldb:mem:lavagna"); setSystemPropertyIfNull(environment, "datasource.username", "sa"); setSystemPropertyIfNull(environment, "datasource.password", ""); setSystemPropertyIfNull(environment, "spring.profiles.active", "dev"); logUse("datasource.dialect"); logUse("datasource.url"); logUse("datasource.username"); logUse("spring.profiles.active"); }
From source file:com.wisemapping.webmvc.ApplicationContextInitializer.java
public void initialize(@NotNull ConfigurableWebApplicationContext ctx) { try {//from ww w . j a v a 2s.c o m final Resource resource = new ServletContextResource(ctx.getServletContext(), "/WEB-INF/app.properties"); final ResourcePropertySource resourcePropertySource = new ResourcePropertySource(resource); ctx.getEnvironment().getPropertySources().addFirst(resourcePropertySource); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:org.jrecruiter.web.config.DefaultApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { final String profile = System.getProperty("jrecruiter-spring-profile"); if (profile == null) { LOGGER.info("System property 'jrecruiter-spring-profile' not set. Setting active profile to '{}'.", SpringContextMode.DemoContextConfiguration.getCode()); applicationContext.getEnvironment() .setActiveProfiles(SpringContextMode.DemoContextConfiguration.getCode()); } else {// w w w.jav a 2s. c om applicationContext.getEnvironment().setActiveProfiles(profile); } final ConfigurableEnvironment environment = applicationContext.getEnvironment(); if (environment.acceptsProfiles("standalone")) { String tingHome = environment.getProperty(Apphome.APP_HOME_DIRECTORY); try { ResourcePropertySource source = new ResourcePropertySource( "file:" + tingHome + File.separator + SystemInformationUtils.JRECRUITER_CONFIG_FILENAME); environment.getPropertySources().addFirst(source); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Properties for standalone mode loaded"); } else { try { environment.getPropertySources() .addFirst(new ResourcePropertySource("classpath:jrecruiter-demo.properties")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Properties for demo mode loaded"); } final Boolean twitterEnabled = environment.getProperty("twitter.enabled", Boolean.class, Boolean.FALSE); if (twitterEnabled) { applicationContext.getEnvironment().addActiveProfile("twitter-enabled"); } System.out.println("::Twitter enabled: " + twitterEnabled); final Boolean mailEnabled = environment.getProperty("mail.enabled", Boolean.class, Boolean.FALSE); if (mailEnabled) { applicationContext.getEnvironment().addActiveProfile("mail-enabled"); } System.out.println("::Mail enabled: " + mailEnabled); final Boolean bitlyEnabled = environment.getProperty("mail.enabled", Boolean.class, Boolean.FALSE); if (bitlyEnabled) { applicationContext.getEnvironment().addActiveProfile("bitly-enabled"); } System.out.println("::Bitly enabled: " + bitlyEnabled); }
From source file:io.kahu.hawaii.config.HawaiiAppContextInitializer.java
private PropertySource<Object> getPropertySource() { List<Resource> resources = new ArrayList<Resource>(); String configurationFiles = System.getProperty("properties.configuration"); String[] files = StringUtils.split(configurationFiles, ","); for (String configFileName : files) { try {/* w w w. jav a2 s . co m*/ File file = new File(configFileName); if (file.exists()) { resources.add(0, new FileSystemResource(file)); } else { System.err.println("Configured properties file '" + configFileName + "' does not exist."); } } catch (Throwable t) { System.err.print("Error loading properties from file '" + configFileName + "': " + t.getMessage()); resources = null; } } try { CompositePropertySource propertySource = new CompositePropertySource("properties"); for (Resource resource : resources) { propertySource.addPropertySource(new ResourcePropertySource(resource)); } return propertySource; } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.security.preauth.WebAnnoApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext aApplicationContext) { WebAnnoLoggingFilter.setLoggingUsername("SYSTEM"); log.info(" _ __ __ ___ "); log.info(" | | /| / /__ / / / _ | ___ ___ ___ "); log.info(" | |/ |/ / -_) _ \\/ __ |/ _ \\/ _ \\/ _ \\"); log.info(" |__/|__/\\__/_.__/_/ |_/_//_/_//_/\\___/"); log.info(SettingsUtil.getVersionString()); ConfigurableEnvironment aEnvironment = aApplicationContext.getEnvironment(); File settings = SettingsUtil.getSettingsFile(); // If settings were found, add them to the environment if (settings != null) { log.info("Settings: " + settings); try {// ww w .j a v a 2 s .co m aEnvironment.getPropertySources() .addFirst(new ResourcePropertySource(new FileSystemResource(settings))); } catch (IOException e) { throw new IllegalStateException(e); } } // Activate bean profile depending on authentication mode if (AUTH_MODE_PREAUTH.equals(aEnvironment.getProperty(PROP_AUTH_MODE))) { aEnvironment.setActiveProfiles(PROFILE_PREAUTH); log.info("Authentication: pre-auth"); } else { aEnvironment.setActiveProfiles(PROFILE_DATABASE); log.info("Authentication: database"); } }
From source file:com.devnexus.ting.web.config.DefaultApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { final CloudEnvironment env = new CloudEnvironment(); if (env.getInstanceInfo() != null) { LOGGER.info("cloud API: " + env.getCloudApiUri()); applicationContext.getEnvironment().setActiveProfiles("cloud", SpringContextMode.DemoContextConfiguration.getCode()); } else {/* w w w . j a va 2s . c o m*/ final String profile = System.getProperty("ting-spring-profile"); if (profile == null) { LOGGER.info("System property 'ting-spring-profile' not set. Setting active profile to '{}'.", SpringContextMode.DemoContextConfiguration.getCode()); applicationContext.getEnvironment() .setActiveProfiles(SpringContextMode.DemoContextConfiguration.getCode()); } else { applicationContext.getEnvironment().setActiveProfiles(profile); } } final ConfigurableEnvironment environment = applicationContext.getEnvironment(); if (environment.acceptsProfiles(SpringProfile.STANDALONE)) { final String tingHome = environment.getProperty(Apphome.APP_HOME_DIRECTORY); final ResourcePropertySource propertySource; final String productionPropertySourceLocation = "file:" + tingHome + File.separator + SystemInformationUtils.TING_CONFIG_FILENAME; try { propertySource = new ResourcePropertySource(productionPropertySourceLocation); } catch (IOException e) { throw new IllegalStateException( "Unable to get ResourcePropertySource '" + productionPropertySourceLocation + "'", e); } environment.getPropertySources().addFirst(propertySource); LOGGER.info("Properties for standalone mode loaded [" + productionPropertySourceLocation + "]"); } else { final String demoPropertySourceLocation = "classpath:ting-demo.properties"; final ResourcePropertySource propertySource; try { propertySource = new ResourcePropertySource(demoPropertySourceLocation); } catch (IOException e) { throw new IllegalStateException( "Unable to get ResourcePropertySource '" + demoPropertySourceLocation + "'", e); } environment.getPropertySources().addFirst(propertySource); LOGGER.info("Properties for demo mode loaded [" + demoPropertySourceLocation + "]"); } final boolean mailEnabled = environment.getProperty("mail.enabled", Boolean.class, Boolean.FALSE); final boolean twitterEnabled = environment.getProperty("twitter.enabled", Boolean.class, Boolean.FALSE); final boolean websocketEnabled = environment.getProperty("websocket.enabled", Boolean.class, Boolean.FALSE); if (mailEnabled) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.MAIL_ENABLED); } if (twitterEnabled) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.TWITTER_ENABLED); } if (websocketEnabled) { applicationContext.getEnvironment().addActiveProfile(SpringProfile.WEBSOCKET_ENABLED); } }
From source file:st.malike.service.storm.LNSBolt.java
@Override public void prepare(Map stormConf, TopologyContext context) { try {// w w w. j a v a 2 s . co m this.config = stormConf; // reinitialize Spring IoC-- a hack AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.getEnvironment().getPropertySources() .addFirst(new ResourcePropertySource("classpath:application.properties")); ctx.scan("st.malike"); ctx.refresh(); demographicSummaryService = ctx.getBean(DemographicSummaryService.class); demographicService = ctx.getBean(DemographicService.class); summaryElasticSearchService = ctx.getBean(SummaryElasticSearchService.class); liveNotificationService = ctx.getBean(LiveNotificationService.class); summaryCalculatorService = ctx.getBean(SummaryCalculatorService.class); } catch (IOException ex) { Logger.getLogger(LNSBolt.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.indeed.imhotep.web.config.PropertiesInitializer.java
protected boolean tryAddPropertySource(ConfigurableApplicationContext applicationContext, MutablePropertySources propSources, String filePath) { if (filePath == null) { return false; }// ww w . j a v a 2 s . c o m Resource propertiesResource = applicationContext.getResource(filePath); if (!propertiesResource.exists()) { return false; } try { ResourcePropertySource propertySource = new ResourcePropertySource(propertiesResource); propSources.addFirst(propertySource); } catch (IOException e) { return false; } log.debug("Successfully added property source: " + filePath); return true; }