Examples of MutablePropertySources


Examples of org.springframework.core.env.MutablePropertySources

    return result;
  }

  private Map<String, PropertySource<?>> getPropertySources() {
    Map<String, PropertySource<?>> map = new LinkedHashMap<String, PropertySource<?>>();
    MutablePropertySources sources = null;
    if (this.environment != null
        && this.environment instanceof ConfigurableEnvironment) {
      sources = ((ConfigurableEnvironment) this.environment).getPropertySources();
    }
    else {
View Full Code Here

Examples of org.springframework.core.env.MutablePropertySources

  public void contextConfigurer() {
    System.setProperty("prop", "it works");
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(BeanTest.class);

    ApplicationContextConfigurer.configure(context, new MutablePropertySources());
    context.refresh();

    BeanTest bean = context.getBean(BeanTest.class);
    assertNotNull(bean);
    assertEquals("it works", bean.named);
View Full Code Here

Examples of org.springframework.core.env.MutablePropertySources

  }

  @Test
  public void systemPropertiesPrecedence() {
    System.setProperty("prop", "system");
    MutablePropertySources propertySources = new MutablePropertySources();
    Map<String, Object> propertySource = new HashMap<String, Object>();
    propertySource.put("prop", "app");

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(BeanTest.class);

    propertySources.addFirst(new MapPropertySource("appProperties", propertySource));

    ApplicationContextConfigurer.configure(context, propertySources);
    context.refresh();

    BeanTest bean = context.getBean(BeanTest.class);
View Full Code Here

Examples of org.springframework.core.env.MutablePropertySources

    final ConfigurableEnvironment env = context.getEnvironment();
    if (propertySources.size() == 0) {
      logger.warn("No property files were found.");
    }
    // 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);
      if (propertySource != null) {
        mutablePropertySources.addLast(propertySource);
      }
    }
    // Enable @Value
    PropertySourcesPlaceholderConfigurer placeholderConfigurer =
        new PropertySourcesPlaceholderConfigurer();
View Full Code Here

Examples of org.springframework.core.env.MutablePropertySources

@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class JpaFixturesIntegrationTest extends AnnotationConfigContextLoader {

  @Override
  protected void customizeContext(final GenericApplicationContext context) {
    MutablePropertySources propertySources = new MutablePropertySources();
    // use mem db and publish a namespace
    Map<String, Object> testProperties = new HashMap<String, Object>();
    testProperties.put("db", "mem");
    testProperties.put("application.ns", getClass().getPackage().getName());

    context.registerBeanDefinition("conversionService", new RootBeanDefinition(
        DefaultConversionService.class));

    propertySources.addFirst(new MapPropertySource("integrationTest", testProperties));

    ApplicationContextConfigurer.configure(context, propertySources);
  }
View Full Code Here

Examples of org.springframework.core.env.MutablePropertySources

    AnnotationConfigApplicationContext context =
        new AnnotationConfigApplicationContext();
    context.register(CamelModule.class, CamelRouteBuilder.class,
        CamelCallback.class, Printer.class);
    ApplicationContextConfigurer.configure(context, new MutablePropertySources());
    context.refresh();

    ProducerTemplate template = context.getBean(ProducerTemplate.class);

    template.sendBody("direct:configurer", "Configurer works!");
View Full Code Here

Examples of org.springframework.core.env.MutablePropertySources

    servletContext.addListener(new ContextLoaderListener(context));

    Pair<MutablePropertySources, Map<String, Object>> propertyConfig =
        propertySources(servletContext.getContextPath(), context);
    MutablePropertySources propertySources = propertyConfig.getLeft();

    configure(propertySources);

    ApplicationContextConfigurer.configure(context, propertySources);
View Full Code Here

Examples of org.springframework.core.env.MutablePropertySources

      specialProps.put(APP_DEFAULT_NAMESPACE, getClass().getPackage().getName());

      // startup class
      specialProps.put(APP_STARTUP_CLASS, getClass().getName());

      MutablePropertySources propertySources = new MutablePropertySources();
      propertySources.addFirst(new MapPropertySource(appName, specialProps));
      for (int i = properties.size() - 1; i >= 0; i--) {
        propertySources.addFirst(asPropertySource(properties.get(i)));
      }

      return Pair.of(propertySources, specialProps);
    } catch (IOException ex) {
      throw new ServletException("The environment cannot be configured.",
View Full Code Here

Examples of org.springframework.core.env.MutablePropertySources

   * @return A {@link PropertiesComponent Camel Component}.
   */
  @SuppressWarnings("rawtypes")
  private static PropertiesComponent camelProperties(final ApplicationContext applicationContext) {
    ConfigurableEnvironment env = (ConfigurableEnvironment) applicationContext.getEnvironment();
    final MutablePropertySources propertySources = env.getPropertySources();
    List<String> names = new ArrayList<String>();
    for (PropertySource<?> propertySource : propertySources) {
      names.add(propertySource.getName());
    }

    PropertiesComponent properties = new PropertiesComponent(
        names.toArray(new String[names.size()]));
    properties.setPropertiesResolver(new PropertiesResolver() {
      @Override
      public Properties resolveProperties(final CamelContext context,
          final boolean ignoreMissingLocation,
          final String... names) throws Exception {
        Properties properties = new Properties();
        // Add in reverse order to preserve precedence.
        for (int i = names.length - 1; i >= 0; i--) {
          PropertySource<?> propertySource = propertySources.get(names[i]);
          if (propertySource instanceof EnumerablePropertySource) {
            String[] propertyNames = ((EnumerablePropertySource) propertySource).getPropertyNames();
            for (String propertyName : propertyNames) {
              properties.put(propertyName, propertySource.getProperty(propertyName));
            }
View Full Code Here

Examples of org.springframework.core.env.MutablePropertySources

   *
   * @param resources Resources to add.
   * @see org.springframework.core.env.PropertySource
   */
  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.