Package org.springframework.core.env

Examples of org.springframework.core.env.MutablePropertySources.addLast()


  @Test
  public void test() {
    MutablePropertySources sources = new MutablePropertySources();
    sources.addLast(new MockPropertySource("b").withProperty("p1", "bValue"));
    sources.addLast(new MockPropertySource("d").withProperty("p1", "dValue"));
    sources.addLast(new MockPropertySource("f").withProperty("p1", "fValue"));

    assertThat(sources.size(), equalTo(3));
    assertThat(sources.contains("a"), is(false));
    assertThat(sources.contains("b"), is(true));
    assertThat(sources.contains("c"), is(false));
View Full Code Here


    assertThat(sources.precedenceOf(PropertySource.named("d")), is(3));
    assertThat(sources.precedenceOf(PropertySource.named("e")), is(4));
    assertThat(sources.precedenceOf(PropertySource.named("f")), is(5));
    assertThat(sources.precedenceOf(PropertySource.named("g")), is(6));

    sources.addLast(new MockPropertySource("a"));
    assertThat(sources.size(), equalTo(7));
    assertThat(sources.precedenceOf(PropertySource.named("b")), is(0));
    assertThat(sources.precedenceOf(PropertySource.named("c")), is(1));
    assertThat(sources.precedenceOf(PropertySource.named("d")), is(2));
    assertThat(sources.precedenceOf(PropertySource.named("e")), is(3));
View Full Code Here

    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        if (propertyResolver == null) {
            try {
                MutablePropertySources sources = new MutablePropertySources();
                PropertySource<?> localPropertySource = new PropertiesPropertySource(EXTENDED_PROPERTIES_SOURCE, mergeProperties());
                sources.addLast(localPropertySource);

                propertyResolver = new PropertySourcesPropertyResolver(sources);

            } catch (IOException e) {
                throw new BeanInitializationException("Could not load properties", e);
View Full Code Here

   */
  protected void configurePropertySources(ConfigurableEnvironment environment,
      String[] args) {
    MutablePropertySources sources = environment.getPropertySources();
    if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) {
      sources.addLast(new MapPropertySource("defaultProperties",
          this.defaultProperties));
    }
    if (this.addCommandLineProperties && args.length > 0) {
      String name = CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME;
      if (sources.contains(name)) {
View Full Code Here

    return resolvers;
  }

  private PropertyResolver getVersionResolver(Class<?> sourceClass) {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new MapPropertySource("version",
        getVersionsMap(sourceClass)));
    return new PropertySourcesPropertyResolver(propertySources);
  }

  private Map<String, Object> getVersionsMap(Class<?> sourceClass) {
View Full Code Here

      }

      MutablePropertySources loaded = loader.getPropertySources();
      if (mergeDefaultSources) {
        for (PropertySource<?> propertySource : this.propertySources) {
          loaded.addLast(propertySource);
        }
      }
      return loaded;
    }
    catch (IOException ex) {
View Full Code Here

    }
    // Add property's by precedence.
    MutablePropertySources mutablePropertySources = env.getPropertySources();
    for (PropertySource<?> propertySource : propertySources) {
      logger.debug("Adding property file: {}", propertySource);
      mutablePropertySources.addLast(propertySource);
    }
    // Move some less-used property source to the end of the chain.
    String[] moveToEnd = {"servletConfigInitParams", "servletContextInitParams", "jndiProperties" };
    for (String propertySourceName : moveToEnd) {
      PropertySource<?> propertySource = mutablePropertySources.remove(propertySourceName);
View Full Code Here

    // Move some less-used property source to the end of the chain.
    String[] moveToEnd = {"servletConfigInitParams", "servletContextInitParams", "jndiProperties" };
    for (String propertySourceName : moveToEnd) {
      PropertySource<?> propertySource = mutablePropertySources.remove(propertySourceName);
      if (propertySource != null) {
        mutablePropertySources.addLast(propertySource);
      }
    }
    // Enable @Value
    PropertySourcesPlaceholderConfigurer placeholderConfigurer =
        new PropertySourcesPlaceholderConfigurer();
View Full Code Here

  public void addPropertySources( Resource... resources ) {
    MutablePropertySources propertySources = new MutablePropertySources();
    for ( Resource resource : resources ) {
      if ( resource.exists() ) {
        try {
          propertySources.addLast( new ResourcePropertySource( resource ) );
        }
        catch ( IOException ioe ) {
          throw new AcrossException( "Failed to load property resource " + resource, ioe );
        }
      }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.