Package org.springframework.core.env

Examples of org.springframework.core.env.CompositePropertySource


      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.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

      }
      else {
        if (existing instanceof ResourcePropertySource) {
          existing = ((ResourcePropertySource) existing).withResourceName();
        }
        CompositePropertySource composite = new CompositePropertySource(name);
        composite.addPropertySource(propertySource.withResourceName());
        composite.addPropertySource(existing);
        propertySources.replace(name, composite);
      }
    }
    else {
      if (this.propertySourceNames.isEmpty()) {
View Full Code Here

    }
    if (this.addCommandLineProperties && args.length > 0) {
      String name = CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME;
      if (sources.contains(name)) {
        PropertySource<?> source = sources.get(name);
        CompositePropertySource composite = new CompositePropertySource(name);
        composite.addPropertySource(new SimpleCommandLinePropertySource(name
            + "-" + args.hashCode(), args));
        composite.addPropertySource(source);
        sources.replace(name, composite);
      }
      else {
        sources.addFirst(new SimpleCommandLinePropertySource(args));
      }
View Full Code Here

  @Test
  public void testBindFromCompositePropertySource() throws Exception {
    this.targetName = "foo";
    setupFactory();
    MutablePropertySources sources = new MutablePropertySources();
    CompositePropertySource composite = new CompositePropertySource("composite");
    composite.addPropertySource(new MapPropertySource("map", Collections
        .singletonMap("foo.map.name", (Object) "blah")));
    sources.addFirst(composite);
    this.factory.setPropertySources(sources);
    this.factory.afterPropertiesSet();
    Foo foo = this.factory.getObject();
View Full Code Here

  }

  @Test
  public void testCompositeValue() {
    PropertySource<?> map = this.propertySources.get("map");
    CompositePropertySource composite = new CompositePropertySource("composite");
    composite.addPropertySource(map);
    this.propertySources.replace("map", composite);
    PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(
        this.propertySources);
    assertEquals("bar", propertyValues.getPropertyValue("foo").getValue());
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testCompositeSource() throws Exception {
    EnvironmentEndpoint report = getEndpointBean();
    CompositePropertySource source = new CompositePropertySource("composite");
    source.addPropertySource(new MapPropertySource("one", Collections.singletonMap(
        "foo", (Object) "bar")));
    source.addPropertySource(new MapPropertySource("two", Collections.singletonMap(
        "foo", (Object) "spam")));
    this.context.getEnvironment().getPropertySources().addFirst(source);
    Map<String, Object> env = report.invoke();
    assertEquals("bar", ((Map<String, Object>) env.get("composite:one")).get("foo"));
  }
View Full Code Here

TOP

Related Classes of org.springframework.core.env.CompositePropertySource

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.