use of org.springframework.core.io.ResourceLoader in project spring-framework by spring-projects.
the class GenericFilterBean method init.
/**
* Standard way of initializing this filter.
* Map config parameters onto bean properties of this filter, and
* invoke subclass initialization.
* @param filterConfig the configuration for this filter
* @throws ServletException if bean properties are invalid (or required
* properties are missing), or if subclass initialization fails.
* @see #initFilterBean
*/
@Override
public final void init(FilterConfig filterConfig) throws ServletException {
Assert.notNull(filterConfig, "FilterConfig must not be null");
this.filterConfig = filterConfig;
// Set bean properties from init parameters.
PropertyValues pvs = new FilterConfigPropertyValues(filterConfig, this.requiredProperties);
if (!pvs.isEmpty()) {
try {
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
ResourceLoader resourceLoader = new ServletContextResourceLoader(filterConfig.getServletContext());
Environment env = this.environment;
if (env == null) {
env = new StandardServletEnvironment();
}
bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, env));
initBeanWrapper(bw);
bw.setPropertyValues(pvs, true);
} catch (BeansException ex) {
String msg = "Failed to set bean properties on filter '" + filterConfig.getFilterName() + "': " + ex.getMessage();
logger.error(msg, ex);
throw new NestedServletException(msg, ex);
}
}
// Let subclasses do whatever initialization they like.
initFilterBean();
if (logger.isDebugEnabled()) {
logger.debug("Filter '" + filterConfig.getFilterName() + "' configured for use");
}
}
use of org.springframework.core.io.ResourceLoader in project pinpoint by naver.
the class ExternalEnvironment method processEnvironment.
public void processEnvironment(ConfigurableEnvironment environment) {
final String profile = environment.getProperty(PinpointProfileEnvironment.PINPOINT_ACTIVE_PROFILE);
if (profile == null) {
throw new IllegalStateException("profile is not set");
}
ResourceLoader resourceLoader = defaultResourceLoader();
Map<String, Object> systemEnvironment = environment.getSystemProperties();
final String externalConfigLocation = getString(systemEnvironment, externalConfigurationKey);
if (externalConfigLocation == null) {
logger.info(String.format("-D%s is not set", externalConfigurationKey));
return;
}
logger.info("load PropertySource name:{}", getName());
PropertiesPropertySourceLoader loader = new PropertiesPropertySourceLoader(profile, resourceLoader);
String sourceName = resolveSourceName(externalConfigurationKey, externalConfigLocation);
String resourcePath = String.format("file:%s", externalConfigLocation);
PropertiesPropertySource propertySource = loader.loadPropertySource(sourceName, Collections.singletonList(resourcePath));
logger.info("Add PropertySource name:{}", sourceName);
environment.getPropertySources().addLast(propertySource);
}
use of org.springframework.core.io.ResourceLoader in project spring-boot by spring-projects.
the class OnWarDeploymentCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ResourceLoader resourceLoader = context.getResourceLoader();
if (resourceLoader instanceof WebApplicationContext) {
WebApplicationContext applicationContext = (WebApplicationContext) resourceLoader;
ServletContext servletContext = applicationContext.getServletContext();
if (servletContext != null) {
return ConditionOutcome.match("Application is deployed as a WAR file.");
}
}
return ConditionOutcome.noMatch(ConditionMessage.forCondition(ConditionalOnWarDeployment.class).because("the application is not deployed as a WAR file."));
}
use of org.springframework.core.io.ResourceLoader in project spring-boot by spring-projects.
the class ClassLoaderFilesResourcePatternResolver method retrieveResourceLoader.
private ResourceLoader retrieveResourceLoader(ApplicationContext applicationContext) {
Field field = ReflectionUtils.findField(applicationContext.getClass(), "resourceLoader", ResourceLoader.class);
if (field == null) {
return null;
}
ReflectionUtils.makeAccessible(field);
return (ResourceLoader) ReflectionUtils.getField(field, applicationContext);
}
use of org.springframework.core.io.ResourceLoader in project spring-boot by spring-projects.
the class SpringBootContextLoader method prepareEnvironment.
private void prepareEnvironment(MergedContextConfiguration config, SpringApplication application, ConfigurableEnvironment environment, boolean applicationEnvironment) {
setActiveProfiles(environment, config.getActiveProfiles(), applicationEnvironment);
ResourceLoader resourceLoader = (application.getResourceLoader() != null) ? application.getResourceLoader() : new DefaultResourceLoader(null);
TestPropertySourceUtils.addPropertiesFilesToEnvironment(environment, resourceLoader, config.getPropertySourceLocations());
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, getInlinedProperties(config));
}
Aggregations