Package org.springframework.core.env

Examples of org.springframework.core.env.MutablePropertySources


        assertEquals("application", d.getName());
    }

    public void testOverridingDefaultTemplateViaConfig() throws Exception {
            ConfigObject config = new ConfigSlurper().parse("grails.sitemesh.default.layout='otherApplication'");
            MutablePropertySources propertySources = new MutablePropertySources();
            propertySources.addLast(new MapPropertySource("grails", config));

            GrailsWebRequest webRequest = buildMockRequest(new PropertySourcesConfig(propertySources));
            webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
            MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
            appCtx.registerMockResource("/grails-app/views/layouts/application.gsp", "<html><body><h1>Default Layout</h1><g:layoutBody /></body></html>");
View Full Code Here


    @Override
    public void initialize(ConfigurableWebApplicationContext applicationContext) {
        MigrateProperties migrateProperties = new MigrateProperties();
        migrateProperties.migrate();

        MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
        propertySources.addFirst(getPropertySource());
        setSystemProperties(applicationContext);
    }
View Full Code Here

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


        MutablePropertySources propertySources = new MutablePropertySources();
        propertySources.addFirst(propertySource1);
        propertySources.addLast(propertySource2);
        System.out.println(propertySources.get("resource").getProperty("encoding"));

        for (PropertySource propertySource : propertySources) {
            System.out.println(propertySource.getProperty("encoding"));
        }
View Full Code Here

   * Setting this property indicates that environment property sources and local
   * properties should be ignored.
   * @see #postProcessBeanFactory
   */
  public void setPropertySources(PropertySources propertySources) {
    this.propertySources = new MutablePropertySources(propertySources);
  }
View Full Code Here

   * sources, and once set, the configurer makes no assumptions about adding additional sources.
   */
  @Override
  public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (this.propertySources == null) {
      this.propertySources = new MutablePropertySources();
      if (this.environment != null) {
        this.propertySources.addLast(
          new PropertySource<Environment>(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
            @Override
            public String getProperty(String key) {
View Full Code Here

    }
  }

  private void addPropertySource(ResourcePropertySource propertySource) {
    String name = propertySource.getName();
    MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment).getPropertySources();
    if (propertySources.contains(name) && this.propertySourceNames.contains(name)) {
      // We've already added a version, we need to extend it
      PropertySource<?> existing = propertySources.get(name);
      if (existing instanceof CompositePropertySource) {
        ((CompositePropertySource) existing).addFirstPropertySource(propertySource.withResourceName());
      }
      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()) {
        propertySources.addLast(propertySource);
      }
      else {
        String firstProcessed = this.propertySourceNames.get(this.propertySourceNames.size() - 1);
        propertySources.addBefore(firstProcessed, propertySource);
      }
    }
    this.propertySourceNames.add(name);
  }
View Full Code Here

  @Test
  public void propertySourceOrder() throws Exception {
    SimpleNamingContextBuilder.emptyActivatedContextBuilder();

    ConfigurableEnvironment env = new StandardServletEnvironment();
    MutablePropertySources sources = env.getPropertySources();

    assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0));
    assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1));
    assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2));
    assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3));
    assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4));
    assertThat(sources.size(), is(5));
  }
View Full Code Here

        ctx.getEnvironment().getPropertySources().contains("p1"));
    assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));

    // assert that the property source was added last to the set of sources
    String name;
    MutablePropertySources sources = ctx.getEnvironment().getPropertySources();
    Iterator<org.springframework.core.env.PropertySource<?>> iterator = sources.iterator();
    do {
      name = iterator.next().getName();
    }
    while(iterator.hasNext());
View Full Code Here

    bf.registerBeanDefinition("testBean",
        genericBeanDefinition(TestBean.class)
          .addPropertyValue("name", "${my.name}")
          .getBeanDefinition());

    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new MockPropertySource().withProperty("my.name", "foo"));

    PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer();
    pc.setPropertySources(propertySources);
    pc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName(), equalTo("foo"));
    assertEquals(pc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
  }
View Full Code Here

    bf.registerBeanDefinition("testBean",
        genericBeanDefinition(TestBean.class)
          .addPropertyValue("name", "${my.name}")
          .getBeanDefinition());

    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new MockPropertySource());

    PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer();
    pc.setPropertySources(propertySources);
    pc.setEnvironment(new MockEnvironment().withProperty("my.name", "env"));
    pc.setIgnoreUnresolvablePlaceholders(true);
    pc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
    assertEquals(pc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
  }
View Full Code Here

TOP

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

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.