Package org.springframework.core.env

Examples of org.springframework.core.env.MapPropertySource


  @Test
  public void orderingDoesntReplaceExisting() throws Exception {
    // SPR-12198: mySource should 'win' as it was registered manually
    AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext();
    MapPropertySource mySource = new MapPropertySource("mine", Collections.singletonMap("testbean.name", "myTestBean"));
    ctxWithoutName.getEnvironment().getPropertySources().addLast(mySource);
    ctxWithoutName.register(ConfigWithFourResourceLocations.class);
    ctxWithoutName.refresh();
    assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name"), equalTo("myTestBean"));
View Full Code Here


  }

  @Test
  public void importWithPlaceholder() throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    PropertySource<?> propertySource = new MapPropertySource("test",
        Collections.<String, Object> singletonMap("test", "springframework"));
    ctx.getEnvironment().getPropertySources().addFirst(propertySource);
    ctx.register(ImportXmlConfig.class);
    ctx.refresh();
    assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
View Full Code Here

  private void addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context,
      MergedContextConfiguration mergedConfig) {
    String[] keyValuePairs = mergedConfig.getPropertySourceProperties();
    if (!ObjectUtils.isEmpty(keyValuePairs)) {
      String name = "test properties " + ObjectUtils.nullSafeToString(keyValuePairs);
      MapPropertySource ps = new MapPropertySource(name, extractEnvironmentProperties(keyValuePairs));
      context.getEnvironment().getPropertySources().addFirst(ps);
    }
  }
View Full Code Here

      @Override
      @SuppressWarnings("unchecked")
      public EnumerablePropertySource<?> asPropertySource() {
        String uniqueName = String.format("%s-%s", PassthruModuleOptionsMetadata.class.getSimpleName(),
            System.identityHashCode(PassthruModuleOptionsMetadata.this));
        return new MapPropertySource(uniqueName, (Map) raw);
      }
    };
  }
View Full Code Here

  private void bindAndValidate(Map<String, String> raw) throws BindException {
    DataBinder dataBinder = new DataBinder(beanWrapper.getWrappedInstance());
    dataBinder.setIgnoreUnknownFields(false);
    dataBinder.setConversionService(conversionService);
    MutablePropertySources mps = new MutablePropertySources();
    mps.addFirst(new MapPropertySource("options", (Map) raw));
    try {
      dataBinder.bind(new PropertySourcesPropertyValues(mps));
    }
    catch (InvalidPropertyException e) {
      dataBinder.getBindingResult().addError(new FieldError("options", e.getPropertyName(), e.getMessage()));
View Full Code Here

    // Now transform them to their fully qualified form
    Map<String, Object> values = new HashMap<String, Object>();
    for (String name : nakedPS.getPropertyNames()) {
      values.put(fullyQualifiedKey(moduleDefinition, name), nakedPS.getProperty(name));
    }
    EnumerablePropertySource<?> modulePS = new MapPropertySource(propertySourceName, values);
    ConfigurableEnvironment moduleEnvironment = new StandardEnvironment();
    // Append the rootEnvironment
    moduleEnvironment.merge(rootEnvironment);
    // The global environment has been loaded by boot too and
    // its PS of interest was also named "applicationConfigurationProperties"
View Full Code Here

        // We'd like to do 'setSearchNames(baseName)', but the environment property
        // has strong precedence and is already set for XD_CONFIG_NAME.
        Map<String, Object> singletonMap = Collections.singletonMap("spring.config.name",
            (Object) baseName);
        environment.getPropertySources().addFirst(
            new MapPropertySource("searchNamesOverride", singletonMap));
        addPropertySources(environment, resourceLoader);
      }
    }.apply();
    return environment;
  }
View Full Code Here

    for (String name : names) {
      getPropertySources().remove(name);
    }

    Map<String, Object> empty = Collections.emptyMap();
    getPropertySources().addLast(new MapPropertySource(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, empty));
    getPropertySources().addLast(new MapPropertySource(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, empty));

  }
View Full Code Here

        map.put(key, raw.toString());
      }
    }

    event.getEnvironment().getPropertySources().replace(COMMAND_LINE_PROPERTY_SOURCE_NAME,
        new MapPropertySource(COMMAND_LINE_PROPERTY_SOURCE_NAME, map));

  }
View Full Code Here

  public void testhandlerWithExpression() {

    @SuppressWarnings("resource")
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

    MapPropertySource propertiesSource = new MapPropertySource("test", Collections.singletonMap("valueExpression",
        (Object) "payload.get('price').asDouble()"));

    applicationContext.getEnvironment().getPropertySources().addLast(propertiesSource);

    applicationContext.register(GaugeHandlerTestsConfig.class);
View Full Code Here

TOP

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

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.