java类org.springframework.context.support.PropertySourcesPlaceholderConfigurer的实例源码

CloudUnitApplicationContext.java 文件源码 项目:devops-cstack 阅读 34 收藏 0 点赞 0 评论 0
@Bean
@Profile("integration")
public static PropertySourcesPlaceholderConfigurer propertiesForIntegration()
        throws Exception {
    String file = "application-integration-local.properties";

    String envIntegration = System.getenv("CLOUDUNIT_JENKINS_CI");
    if ("true".equalsIgnoreCase(envIntegration)) {
        file = "application-integration.properties";
    }

    PropertySourcesPlaceholderConfigurer pspc =
            new PropertySourcesPlaceholderConfigurer();
    pspc.setLocations(getResources(file));
    pspc.setIgnoreUnresolvablePlaceholders(true);
    pspc.setLocalOverride(true);
    return pspc;
}
GlobalPropertySources.java 文件源码 项目:xproject 阅读 25 收藏 0 点赞 0 评论 0
protected void mergePropertySource() throws Exception {
    if (this.environment != null) {
        this.addLast(new PropertySource<Environment>(PropertySourcesPlaceholderConfigurer.ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
            public String getProperty(String key) {
                return this.source.getProperty(key);
            }
        });
    } else {
        logger.warn("The injected environment was null!");
    }
    if (this.locations != null && this.locations.length > 0) {
        Properties localProperties = new Properties();
        loadProperties(localProperties);
        PropertySource<?> localPropertySource = new PropertiesPropertySource(PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, localProperties);
        if (this.localOverride) {
            this.addFirst(localPropertySource);
        } else {
            this.addLast(localPropertySource);
        }
    }
}
ApolloConfigRegistrar.java 文件源码 项目:apollo-custom 阅读 25 收藏 0 点赞 0 评论 0
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
  AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata
      .getAnnotationAttributes(EnableApolloConfig.class.getName()));
  String[] namespaces = attributes.getStringArray("value");
  int order = attributes.getNumber("order");
  PropertySourcesProcessor.addNamespaces(Lists.newArrayList(namespaces), order);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
      PropertySourcesPlaceholderConfigurer.class);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesProcessor.class.getName(),
      PropertySourcesProcessor.class);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
      ApolloAnnotationProcessor.class);
}
LodsveCoreConfiguration.java 文件源码 项目:lodsve-framework 阅读 31 收藏 0 点赞 0 评论 0
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
    PropertySourcesPlaceholderConfigurer placeholderConfigurer = new PropertySourcesPlaceholderConfigurer();
    placeholderConfigurer.setFileEncoding("UTF-8");

    Properties properties = EnvLoader.getEnvs();
    if (properties.isEmpty()) {
        ParamsHome.getInstance().init(StringUtils.EMPTY);
        EnvLoader.init();
        IniLoader.init();

        properties = EnvLoader.getEnvs();
    }

    placeholderConfigurer.setProperties(properties);

    return placeholderConfigurer;
}
ApolloConfigRegistrar.java 文件源码 项目:apollo 阅读 26 收藏 0 点赞 0 评论 0
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
  AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata
      .getAnnotationAttributes(EnableApolloConfig.class.getName()));
  String[] namespaces = attributes.getStringArray("value");
  int order = attributes.getNumber("order");
  PropertySourcesProcessor.addNamespaces(Lists.newArrayList(namespaces), order);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
      PropertySourcesPlaceholderConfigurer.class);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesProcessor.class.getName(),
      PropertySourcesProcessor.class);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
      ApolloAnnotationProcessor.class);
}
EmbeddedWebApplicationContextTests.java 文件源码 项目:spring-boot-concourse 阅读 29 收藏 0 点赞 0 评论 0
@Test
public void postProcessEmbeddedServletContainerFactory() throws Exception {
    RootBeanDefinition bd = new RootBeanDefinition(
            MockEmbeddedServletContainerFactory.class);
    MutablePropertyValues pv = new MutablePropertyValues();
    pv.add("port", "${port}");
    bd.setPropertyValues(pv);
    this.context.registerBeanDefinition("embeddedServletContainerFactory", bd);

    PropertySourcesPlaceholderConfigurer propertySupport = new PropertySourcesPlaceholderConfigurer();
    Properties properties = new Properties();
    properties.put("port", 8080);
    propertySupport.setProperties(properties);
    this.context.registerBeanDefinition("propertySupport",
            beanDefinition(propertySupport));

    this.context.refresh();
    assertThat(getEmbeddedServletContainerFactory().getContainer().getPort())
            .isEqualTo(8080);
}
EmbeddedWebApplicationContextTests.java 文件源码 项目:https-github.com-g0t4-jenkins2-course-spring-boot 阅读 26 收藏 0 点赞 0 评论 0
@Test
public void postProcessEmbeddedServletContainerFactory() throws Exception {
    RootBeanDefinition bd = new RootBeanDefinition(
            MockEmbeddedServletContainerFactory.class);
    MutablePropertyValues pv = new MutablePropertyValues();
    pv.add("port", "${port}");
    bd.setPropertyValues(pv);
    this.context.registerBeanDefinition("embeddedServletContainerFactory", bd);

    PropertySourcesPlaceholderConfigurer propertySupport = new PropertySourcesPlaceholderConfigurer();
    Properties properties = new Properties();
    properties.put("port", 8080);
    propertySupport.setProperties(properties);
    this.context.registerBeanDefinition("propertySupport",
            beanDefinition(propertySupport));

    this.context.refresh();
    assertThat(getEmbeddedServletContainerFactory().getContainer().getPort())
            .isEqualTo(8080);
}
ConfigValueBeanFactoryPostProcessor.java 文件源码 项目:setaria 阅读 27 收藏 0 点赞 0 评论 0
public void postProcess(ConfigurableListableBeanFactory beanFactory) {
    // 注册 Spring 属性配置
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    MutablePropertySources mutablePropertySources = new MutablePropertySources();
    mutablePropertySources.addLast(new PropertySource<String>(Configs.class.getName()) {
        @Override
        public String getProperty(String name) {
            return Configs.getString(name);
        }
    });
    configurer.setPropertySources(mutablePropertySources);
    configurer.postProcessBeanFactory(beanFactory);

    /*
     * 注册 @ConfigValue 处理器. ConfigValueBeanPostProcessor 实现了 ApplicationListener 接口, 不能使用
     * beanFactory.addBeanPostProcessor() 来注册实例.
     */
    beanFactory.registerSingleton(ConfigValueBeanPostProcessor.class.getName(),
            new ConfigValueBeanPostProcessor(beanFactory));
}
PlaceholderResolved.java 文件源码 项目:elastic-config 阅读 30 收藏 0 点赞 0 评论 0
public Optional<Resource[]> getPlaceholderConfigurerResources() {

        List<Resource> resources = Lists.newArrayList();
        Iterator<Entry<String, PropertySourcesPlaceholderConfigurer>> iterator = placeholderMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<String, PropertySourcesPlaceholderConfigurer> entry = iterator.next();
            Optional<Resource[]> optional = this.<Resource[]> getPropertyValue(entry.getValue(),
                PropertySourcesEnum.LOCATIONS.getName());

            if (optional.isPresent()) {
                resources.addAll(Arrays.asList(optional.get()));
            }
        }

        return Optional.fromNullable(resources.toArray(new Resource[0]));
    }
ConfigPropertyResolver.java 文件源码 项目:configx 阅读 29 收藏 0 点赞 0 评论 0
private PropertySources deducePropertySources() {
    PropertySourcesPlaceholderConfigurer configurer = getSinglePropertySourcesPlaceholderConfigurer();
    if (configurer != null) {
        // Flatten the sources into a single list so they can be iterated
        return new FlatPropertySources(configurer.getAppliedPropertySources());
    }
    if (this.environment instanceof ConfigurableEnvironment) {
        MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment)
                .getPropertySources();
        return new FlatPropertySources(propertySources);
    }
    // empty, so not very useful, but fulfils the contract
    return new MutablePropertySources();
}
ConfigPropertyResolver.java 文件源码 项目:configx 阅读 35 收藏 0 点赞 0 评论 0
private PropertySourcesPlaceholderConfigurer getSinglePropertySourcesPlaceholderConfigurer() {
    // Take care not to cause early instantiation of all FactoryBeans
    if (this.beanFactory instanceof ListableBeanFactory) {
        ListableBeanFactory listableBeanFactory = (ListableBeanFactory) this.beanFactory;
        Map<String, PropertySourcesPlaceholderConfigurer> beans = listableBeanFactory
                .getBeansOfType(PropertySourcesPlaceholderConfigurer.class, false,
                        false);
        if (beans.size() == 1) {
            return beans.values().iterator().next();
        }
    }
    return null;
}
CloudUnitApplicationContext.java 文件源码 项目:devops-cstack 阅读 23 收藏 0 点赞 0 评论 0
@Bean
@Profile("vagrant")
public static PropertySourcesPlaceholderConfigurer properties()
        throws Exception {
    String file = "application-vagrant.properties";
    PropertySourcesPlaceholderConfigurer pspc =
            new PropertySourcesPlaceholderConfigurer();
    pspc.setLocations(getResources(file));
    pspc.setIgnoreUnresolvablePlaceholders(true);
    pspc.setLocalOverride(true);
    return pspc;
}
CloudUnitApplicationContext.java 文件源码 项目:devops-cstack 阅读 31 收藏 0 点赞 0 评论 0
@Bean
@Profile("production")
public static PropertySourcesPlaceholderConfigurer propertiesForProduction()
        throws Exception {
    String file = "application-production.properties";
    PropertySourcesPlaceholderConfigurer pspc =
            new PropertySourcesPlaceholderConfigurer();
    pspc.setLocations(getResources(file));
    pspc.setIgnoreUnresolvablePlaceholders(true);
    pspc.setLocalOverride(true);
    return pspc;
}
CloudUnitApplicationContext.java 文件源码 项目:devops-cstack 阅读 31 收藏 0 点赞 0 评论 0
@Bean
@Profile("vagrant-demo")
public static PropertySourcesPlaceholderConfigurer propertiesForDemo()
        throws Exception {
    String file = "application-vagrant-demo.properties";
    PropertySourcesPlaceholderConfigurer pspc =
            new PropertySourcesPlaceholderConfigurer();
    pspc.setLocations(getResources(file));
    pspc.setIgnoreUnresolvablePlaceholders(true);
    pspc.setLocalOverride(true);
    return pspc;
}
CloudUnitApplicationContext.java 文件源码 项目:devops-cstack 阅读 26 收藏 0 点赞 0 评论 0
@Bean
@Profile("test")
public static PropertySourcesPlaceholderConfigurer propertiesForTest()
        throws Exception {
    PropertySourcesPlaceholderConfigurer pspc =
            new PropertySourcesPlaceholderConfigurer();
    Resource[] resources = new Resource[]
            {new ClassPathResource("application-test.properties")};
    pspc.setLocations(resources);
    pspc.setIgnoreUnresolvablePlaceholders(true);
    pspc.setLocalOverride(true);
    return pspc;
}
ApplicationContext.java 文件源码 项目:scrumtracker2017 阅读 62 收藏 0 点赞 0 评论 0
@Bean
public static PropertySourcesPlaceholderConfigurer properties()
{
    PropertySourcesPlaceholderConfigurer propertySources = new PropertySourcesPlaceholderConfigurer();
    //propertySources.setIgnoreUnresolvablePlaceholders(true);
    return propertySources;
}
PropertyConfig.java 文件源码 项目:learn-spring-5 阅读 29 收藏 0 点赞 0 评论 0
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
    PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =
            new PropertySourcesPlaceholderConfigurer();
    return propertySourcesPlaceholderConfigurer;

}
MangoConfigFactory.java 文件源码 项目:mango-spring-boot-starter 阅读 27 收藏 0 点赞 0 评论 0
private static PropertySources deducePropertySources(DefaultListableBeanFactory beanFactory) {
    PropertySourcesPlaceholderConfigurer configurer = getSinglePropertySourcesPlaceholderConfigurer(beanFactory);
    if (configurer != null) {
        return new FlatPropertySources(configurer.getAppliedPropertySources());
    }
    Environment environment = new StandardEnvironment();
    MutablePropertySources propertySources = ((ConfigurableEnvironment) environment).getPropertySources();
    return new FlatPropertySources(propertySources);

}
MangoConfigFactory.java 文件源码 项目:mango-spring-boot-starter 阅读 27 收藏 0 点赞 0 评论 0
private static PropertySourcesPlaceholderConfigurer getSinglePropertySourcesPlaceholderConfigurer(DefaultListableBeanFactory beanFactory) {
    Map<String, PropertySourcesPlaceholderConfigurer> beans = beanFactory.getBeansOfType(PropertySourcesPlaceholderConfigurer.class, false, false);
    if (beans.size() == 1) {
        return beans.values().iterator().next();
    }
    return null;
}
PropertyPlaceholderBeanDefinitionParser.java 文件源码 项目:lams 阅读 29 收藏 0 点赞 0 评论 0
@Override
protected Class<?> getBeanClass(Element element) {
    // As of Spring 3.1, the default value of system-properties-mode has changed from
    // 'FALLBACK' to 'ENVIRONMENT'. This latter value indicates that resolution of
    // placeholders against system properties is a function of the Environment and
    // its current set of PropertySources
    if (element.getAttribute(SYSTEM_PROPERTIES_MODE_ATTRIB).equals(SYSTEM_PROPERTIES_MODE_DEFAULT)) {
        return PropertySourcesPlaceholderConfigurer.class;
    }

    // the user has explicitly specified a value for system-properties-mode. Revert
    // to PropertyPlaceholderConfigurer to ensure backward compatibility.
    return PropertyPlaceholderConfigurer.class;
}
CustomYamlConfig.java 文件源码 项目:RFTBackend 阅读 31 收藏 0 点赞 0 评论 0
@Bean
public PropertySourcesPlaceholderConfigurer properties() {
    PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
    YamlPropertiesFactoryBean yamlPropertiesFactory = new YamlPropertiesFactoryBean();
    ConfigurationFileResourceResolver configurationFileResourceResolver = new ConfigurationFileResourceResolver();

    yamlPropertiesFactory.setResources(configurationFileResourceResolver.getResourceArray());
    propertySourcesPlaceholderConfigurer.setProperties(yamlPropertiesFactory.getObject());

    return propertySourcesPlaceholderConfigurer;
}
WebConfig.java 文件源码 项目:flow-platform 阅读 29 收藏 0 点赞 0 评论 0
@Bean
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
    AppResourceLoader propertyLoader = new PropertyResourceLoader();

    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setIgnoreResourceNotFound(Boolean.FALSE);
    configurer.setLocation(propertyLoader.find());

    return configurer;
}
WebConfig.java 文件源码 项目:flow-platform 阅读 32 收藏 0 点赞 0 评论 0
@Bean
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
    AppResourceLoader propertyLoader = new PropertyResourceLoader();
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setIgnoreResourceNotFound(Boolean.FALSE);
    configurer.setLocation(propertyLoader.find());
    return configurer;
}
AemServiceConfiguration.java 文件源码 项目:jwala 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Make vars.properties available to spring integration configuration
 * System properties are only used if there is no setting in vars.properties.
 */
@Bean(name = "aemServiceConfigurationPropertiesConfigurer")
public static PropertySourcesPlaceholderConfigurer configurer() {
    PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
    ppc.setLocation(new ClassPathResource("META-INF/spring/jwala-defaults.properties"));
    ppc.setLocalOverride(true);
    ppc.setProperties(ApplicationProperties.getProperties());
    return ppc;
}
ConfigPropertySourcesProcessor.java 文件源码 项目:apollo-custom 阅读 28 收藏 0 点赞 0 评论 0
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
      PropertySourcesPlaceholderConfigurer.class);
  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
      ApolloAnnotationProcessor.class);
}
ConfigurationPropertiesBindingPostProcessor.java 文件源码 项目:spring-boot-concourse 阅读 33 收藏 0 点赞 0 评论 0
private PropertySourcesPlaceholderConfigurer getSinglePropertySourcesPlaceholderConfigurer() {
    // Take care not to cause early instantiation of all FactoryBeans
    if (this.beanFactory instanceof ListableBeanFactory) {
        ListableBeanFactory listableBeanFactory = (ListableBeanFactory) this.beanFactory;
        Map<String, PropertySourcesPlaceholderConfigurer> beans = listableBeanFactory
                .getBeansOfType(PropertySourcesPlaceholderConfigurer.class, false,
                        false);
        if (beans.size() == 1) {
            return beans.values().iterator().next();
        }
    }
    return null;
}
PlaceholderResolved.java 文件源码 项目:elastic-config 阅读 34 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
@SneakyThrows
private <T> Optional<T> getPropertyValue(PropertySourcesPlaceholderConfigurer placeholderConfigurer, String property) {
    Field field = ReflectionUtils.findField(placeholderConfigurer.getClass(), property);
    ReflectionUtils.makeAccessible(field);
    return Optional.fromNullable((T) field.get(placeholderConfigurer));
}
AutoConfigurationReproTests.java 文件源码 项目:spring-boot-concourse 阅读 29 收藏 0 点赞 0 评论 0
@Test
public void doesNotEarlyInitializeFactoryBeans() throws Exception {
    SpringApplication application = new SpringApplication(EarlyInitConfig.class,
            PropertySourcesPlaceholderConfigurer.class,
            EmbeddedServletContainerAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class);
    this.context = application.run("--server.port=0");
    String bean = (String) this.context.getBean("earlyInit");
    assertThat(bean).isEqualTo("bucket");
}
ConfigPropertySourcesProcessor.java 文件源码 项目:apollo 阅读 28 收藏 0 点赞 0 评论 0
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
      PropertySourcesPlaceholderConfigurer.class);
  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
      ApolloAnnotationProcessor.class);
}
PlaceholderResolved.java 文件源码 项目:elastic-config 阅读 32 收藏 0 点赞 0 评论 0
/**
 * 易变属性源
 * 
 * @param placeholderConfigurer 占位符配置器
 * @return 易变属性源
 */
private MutablePropertySources mergePropertySources(PropertySourcesPlaceholderConfigurer placeholderConfigurer) {

    Optional<MutablePropertySources> multablePropertySources = getPropertySourcesSources(placeholderConfigurer);

    if (multablePropertySources.isPresent()) {
        multablePropertySources.get().addLast(registryPropertySource);
        return multablePropertySources.get();
    }

    return this.builder(placeholderConfigurer).environmentSources().localPropertiesSources().elastiConfigSources()
        .bulid();
}


问题


面经


文章

微信
公众号

扫码关注公众号