Package org.springframework.core.io.support

Examples of org.springframework.core.io.support.ResourcePropertySource


      String name = (String) propertySourceAttributes.get("name");
      String[] locations = (String[]) propertySourceAttributes.get("value");
      ClassLoader classLoader = this.resourceLoader.getClassLoader();
      for (String location : locations) {
        location = this.environment.resolveRequiredPlaceholders(location);
        ResourcePropertySource ps = StringUtils.hasText(name) ?
            new ResourcePropertySource(name, location, classLoader) :
            new ResourcePropertySource(location, classLoader);
        this.propertySources.push(ps);
      }
    }

    // process any @ComponentScan annotions
View Full Code Here


        locations[i] = this.environment.resolveRequiredPlaceholders(locations[i]);
      }
      ClassLoader classLoader = this.resourceLoader.getClassLoader();
      if (!StringUtils.hasText(name)) {
        for (String location : locations) {
          this.propertySources.push(new ResourcePropertySource(location, classLoader));
        }
      }
      else {
        if (nLocations == 1) {
          this.propertySources.push(new ResourcePropertySource(name, locations[0], classLoader));
        }
        else {
          CompositePropertySource ps = new CompositePropertySource(name);
          for (String location : locations) {
            ps.addPropertySource(new ResourcePropertySource(location, classLoader));
          }
          this.propertySources.push(ps);
        }
      }
    }
View Full Code Here

        Map<String, Object> map = new HashMap<>();
        map.put("encoding", "gbk");
        PropertySource propertySource1 = new MapPropertySource("map", map);
        System.out.println(propertySource1.getProperty("encoding"));

        ResourcePropertySource propertySource2 = new ResourcePropertySource("resource", "classpath:resources.properties");
        System.out.println(propertySource2.getProperty("encoding"));
    }
View Full Code Here

        Map<String, Object> map = new HashMap<>();
        map.put("encoding", "gbk");
        PropertySource propertySource1 = new MapPropertySource("map", map);

        ResourcePropertySource propertySource2 = new ResourcePropertySource("resource", "classpath:resources.properties");

        CompositePropertySource compositePropertySource = new CompositePropertySource("composite");
        compositePropertySource.addPropertySource(propertySource1);
        compositePropertySource.addPropertySource(propertySource2);
        System.out.println(compositePropertySource.getProperty("encoding"));
View Full Code Here

        Map<String, Object> map = new HashMap<>();
        map.put("encoding", "gbk");
        PropertySource propertySource1 = new MapPropertySource("map", map);

        ResourcePropertySource propertySource2 = new ResourcePropertySource(
                "resource", "classpath:resources.properties");


        MutablePropertySources propertySources = new MutablePropertySources();
        propertySources.addFirst(propertySource1);
View Full Code Here

    public void test() throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("encoding", "gbk");
        PropertySource propertySource1 = new MapPropertySource("map", map);

        ResourcePropertySource propertySource2 = new ResourcePropertySource(
                "resource", "classpath:resources.properties");


        MutablePropertySources propertySources = new MutablePropertySources();
View Full Code Here

    Assert.isTrue(locations.length > 0, "At least one @PropertySource(value) location is required");
    for (String location : locations) {
      try {
        String resolvedLocation = this.environment.resolveRequiredPlaceholders(location);
        Resource resource = this.resourceLoader.getResource(resolvedLocation);
        ResourcePropertySource rps = (StringUtils.hasText(name) ?
            new ResourcePropertySource(name, resource) : new ResourcePropertySource(resource));
        addPropertySource(rps);
      }
      catch (IllegalArgumentException ex) {
        // from resolveRequiredPlaceholders
        if (!ignoreResourceNotFound) {
View Full Code Here

      ConfigurableEnvironment environment = context.getEnvironment();
      String[] locations = mergedConfig.getPropertySourceLocations();
      for (String location : locations) {
        String resolvedLocation = environment.resolveRequiredPlaceholders(location);
        Resource resource = context.getResource(resolvedLocation);
        ResourcePropertySource ps = new ResourcePropertySource(resource);
        environment.getPropertySources().addFirst(ps);
      }
    }
    catch (IOException e) {
      throw new IllegalStateException("Failed to add PropertySource to Environment", e);
View Full Code Here

    public void initialize(final ConfigurableApplicationContext applicationContext) {
        final ConfigurableEnvironment environment = applicationContext.getEnvironment();
        String envTarget = null;
        try {
            envTarget = getEnvTarget(environment);
            environment.getPropertySources().addFirst(new ResourcePropertySource("classpath:env-" + envTarget + ".properties"));

            final String activeProfiles = environment.getProperty("spring.profiles.active");
            logger.info("The active profiles are: {}", activeProfiles);

            environment.setActiveProfiles(activeProfiles.split(","));
View Full Code Here

     * This enables overriding the env-${envTarget}.properties location, which is by default resolved internally from the classpath. The entire purpose of overriding this specific properties file is to be able to control
     * the active Spring profile without defining system wide variables on the OS that runs staging
     */
    private final String getTargetFromOverride() {
        try {
            final ResourcePropertySource overrideProperties = new ResourcePropertySource("file:///opt/override/overrides.properties");
            return (String) overrideProperties.getProperty(ENV_TARGET);
        } catch (final IOException e) {
            logger.trace("The file overrides.properties is not accessible. No property overridden by external properties");
        }

        return null;
View Full Code Here

TOP

Related Classes of org.springframework.core.io.support.ResourcePropertySource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.