本文整理汇总了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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}