当前位置: 首页>>代码示例>>Java>>正文


Java ResourcePropertySource类代码示例

本文整理汇总了Java中org.springframework.core.io.support.ResourcePropertySource的典型用法代码示例。如果您正苦于以下问题:Java ResourcePropertySource类的具体用法?Java ResourcePropertySource怎么用?Java ResourcePropertySource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ResourcePropertySource类属于org.springframework.core.io.support包,在下文中一共展示了ResourcePropertySource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPropertySource

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
public static Optional<ResourcePropertySource> createPropertySource() {
    try (final AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
        ctx.register(AwsCloudRuntimeConfig.class);
        ctx.register(RuntimeEnvironmentUtil.class);
        ctx.refresh();
        ctx.start();

        if (ctx.getBean(RuntimeEnvironmentUtil.class).isProductionEnvironment()) {
            final String s3config = ctx.getEnvironment().getProperty("aws.config.s3location");
            final Resource resource = ctx.getBean(SimpleStorageResourceLoader.class).getResource(s3config);
            return Optional.of(new ResourcePropertySource("aws", resource));
        }

        return Optional.empty();

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:20,代码来源:AwsCloudRuntimeConfig.java

示例2: initialize

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {

    try {
        String env = System.getenv(ENVIRONMENT);

        if (env == null) {
            env = System.getProperty(ENVIRONMENT, "dev");
        }

        ConfigurableEnvironment environment = applicationContext.getEnvironment();

        environment.getPropertySources()
            .addLast(new ResourcePropertySource("classpath:application-" + env + ".properties"));
        environment.getPropertySources().addLast(new ResourcePropertySource("classpath:application.properties"));
    } catch (IOException ex) {
        LOG.warn("Unable to load application properties!", ex);
    }
}
 
开发者ID:Contargo,项目名称:iris,代码行数:20,代码来源:ContargoApplicationInitializer.java

示例3: tryAddPropertySource

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
protected boolean tryAddPropertySource(final ConfigurableApplicationContext applicationContext,
                                       final MutablePropertySources propSources,
                                       final String filePath) {

    if (filePath == null) {
        return false;
    }
    Resource propertiesResource = applicationContext.getResource(filePath);
    if (!propertiesResource.exists()) {
        return false;
    }
    try {
        ResourcePropertySource propertySource = new ResourcePropertySource(propertiesResource);
        propSources.addFirst(propertySource);
    } catch (IOException e) {
        return false;
    }
    return true;
}
 
开发者ID:indeedeng,项目名称:proctor-pipet,代码行数:20,代码来源:PropertiesInitializer.java

示例4: tryAddPropertySource

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
protected boolean tryAddPropertySource(ConfigurableApplicationContext applicationContext, MutablePropertySources propSources, String filePath) {
    if(filePath == null) {
        return false;
    }
    Resource propertiesResource = applicationContext.getResource(filePath);
    if(!propertiesResource.exists()) {
        return false;
    }
    try {
        ResourcePropertySource propertySource = new ResourcePropertySource(propertiesResource);
        propSources.addFirst(propertySource);
    } catch (IOException e) {
        return false;
    }
    log.debug("Successfully added property source: " + filePath);
    return true;
}
 
开发者ID:indeedeng,项目名称:iupload,代码行数:18,代码来源:PropertiesInitializer.java

示例5: getPropertySources

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
public List<PropertySource<?>> getPropertySources() {
	List<PropertySource<?>> propertySources = new LinkedList<PropertySource<?>>();
	for (Map.Entry<String, List<ResourcePropertySource>> entry : this.propertySources.entrySet()) {
		propertySources.add(0, collatePropertySources(entry.getKey(), entry.getValue()));
	}
	return propertySources;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:ConfigurationClassParser.java

示例6: collatePropertySources

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
private PropertySource<?> collatePropertySources(String name, List<ResourcePropertySource> propertySources) {
	if (propertySources.size() == 1) {
		return propertySources.get(0).withName(name);
	}
	CompositePropertySource result = new CompositePropertySource(name);
	for (int i = propertySources.size() - 1; i >= 0; i--) {
		result.addPropertySource(propertySources.get(i));
	}
	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:ConfigurationClassParser.java

示例7: onStartup

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
public void onStartup(ServletContext servletContext) throws ServletException {
    LOGGER.trace("Initializing Flow Control Center for %s", servletContext.getServerInfo());

    // get class loader
    ClassLoader appClassLoader = appClassLoader();

    // Create ApplicationContext and set class loader
    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.setClassLoader(appClassLoader);

    applicationContext.register(WebConfig.class);
    Set<Class<?>> cloudClasses = CloudJarResourceLoader.configClasses(appClassLoader);
    if (!cloudClasses.isEmpty()) {
        applicationContext.register((cloudClasses.toArray(new Class<?>[cloudClasses.size()])));
    }

    applicationContext.setServletContext(servletContext);

    // set app property resource
    try {
        AppResourceLoader propertyLoader = new PropertyResourceLoader();
        applicationContext
            .getEnvironment()
            .getPropertySources()
            .addFirst(new ResourcePropertySource(propertyLoader.find()));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    // Add the servlet mapping manually and make it initialize automatically
    DispatcherServlet dispatcherServlet = new DispatcherServlet(applicationContext);
    ServletRegistration.Dynamic servlet = servletContext.addServlet("mvc-dispatcher", dispatcherServlet);

    servlet.addMapping("/");
    servlet.setAsyncSupported(true);
    servlet.setLoadOnStartup(1);
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:38,代码来源:AppInit.java

示例8: initialize

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    try {
        applicationContext
            .getEnvironment()
            .getPropertySources()
            .addFirst(new ResourcePropertySource(new PropertyResourceLoader().find()));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:12,代码来源:TestBase.java

示例9: createRequestTemplate

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
protected static MMLWebFeatureServiceRequestTemplate createRequestTemplate() throws IOException {
    ClassPathResource classPathResource = new ClassPathResource("configuration/application.properties");
    ResourcePropertySource propertySource = new ResourcePropertySource(classPathResource);
    String uri = propertySource.getProperty("wfs.mml.uri").toString();
    String username = propertySource.getProperty("wfs.mml.username").toString();
    String password = propertySource.getProperty("wfs.mml.password").toString();

    MMLProperties mmlProperties = new MMLProperties(uri, username, password);
    ClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();

    return new MMLWebFeatureServiceRequestTemplate(mmlProperties, requestFactory);
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:13,代码来源:AbstractMMLServiceTest.java

示例10: addPropertySource

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:ConfigurationClassParser.java

示例11: onApplicationEvent

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
  ConfigurableEnvironment environment = event.getEnvironment();
  String propertySource = environment.getProperty("c2mon.client.conf.url");

  if (propertySource != null) {
    try {
      environment.getPropertySources().addAfter("systemEnvironment", new ResourcePropertySource(propertySource));
    } catch (IOException e) {
      throw new RuntimeException("Could not read property source", e);
    }
  }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:14,代码来源:C2monApplicationListener.java

示例12: onApplicationEvent

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
/**
 * Listens for the {@link ApplicationEnvironmentPreparedEvent} and injects
 * ${c2mon.server.properties} into the environment with the highest precedence
 * (if it exists). This is in order to allow users to point to an external
 * properties file via ${c2mon.server.properties}.
 */
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
  ConfigurableEnvironment environment = event.getEnvironment();
  String propertySource = environment.getProperty("c2mon.server.properties");

  if (propertySource != null) {
    try {
      environment.getPropertySources().addAfter("systemEnvironment", new ResourcePropertySource(propertySource));
    } catch (IOException e) {
      throw new RuntimeException("Could not read property source", e);
    }
  }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:20,代码来源:CommonModule.java

示例13: propertySourcesPlaceholderConfigurer

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
/**
 * Without this bean declared, the @Value placeholder above will not be resolved properly.
 *
 * Using @PropertySource by itself will not work; nor will it work if this method is not declared static.
 *
 * See {@link org.springframework.context.annotation.PropertySource} JavaDoc for more info.
 */
@Bean
static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
    PropertySourcesPlaceholderConfigurer result = new PropertySourcesPlaceholderConfigurer();
    MutablePropertySources sources = new MutablePropertySources();
    sources.addFirst(new ResourcePropertySource("classpath:app.properties"));
    result.setPropertySources(sources);
    result.setIgnoreUnresolvablePlaceholders(false);
    return result;
}
 
开发者ID:amdw,项目名称:boilerplate,代码行数:17,代码来源:InternalConfig.java

示例14: propertySourcesPlaceholderConfigurer

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
/**
 * Without this method, e.g. if you try to use @PropertySource("classpath:app.properties") on the
 * WrongConfig class, you don't even get an error at all - try it! The behaviour is the same as the below
 * with setIgnoreUnresolvablePlaceholders(true).
 */
@Bean
static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
    PropertySourcesPlaceholderConfigurer result = new PropertySourcesPlaceholderConfigurer();
    MutablePropertySources sources = new MutablePropertySources();
    sources.addFirst(new ResourcePropertySource("classpath:app.properties"));
    result.setPropertySources(sources);
    result.setIgnoreUnresolvablePlaceholders(false);
    return result;
}
 
开发者ID:amdw,项目名称:boilerplate,代码行数:15,代码来源:SpringMissingPropertyDemo.java

示例15: addPropertySource

import org.springframework.core.io.support.ResourcePropertySource; //导入依赖的package包/类
private void addPropertySource(PropertySource<?> 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);
		PropertySource<?> newSource = (propertySource instanceof ResourcePropertySource ?
				((ResourcePropertySource) propertySource).withResourceName() : propertySource);
		if (existing instanceof CompositePropertySource) {
			((CompositePropertySource) existing).addFirstPropertySource(newSource);
		}
		else {
			if (existing instanceof ResourcePropertySource) {
				existing = ((ResourcePropertySource) existing).withResourceName();
			}
			CompositePropertySource composite = new CompositePropertySource(name);
			composite.addPropertySource(newSource);
			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);
}
 
开发者ID:txazo,项目名称:spring,代码行数:33,代码来源:ConfigurationClassParser.java


注:本文中的org.springframework.core.io.support.ResourcePropertySource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。