List of usage examples for org.springframework.context.annotation ConditionContext getResourceLoader
ResourceLoader getResourceLoader();
From source file:com.github.mrstampy.gameboot.util.resource.AbstractFallbackResourceCondition.java
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { ResourceLoader loader = context.getResourceLoader(); if (hasOverride(loader)) return false; boolean b = loader.getResource(fallback).exists(); if (b)// w ww . j a va 2 s. c o m ResourceLogger.log(fallback); return b; }
From source file:lodsve.core.condition.OnWebApplicationCondition.java
private ConditionOutcome isWebApplication(ConditionContext context, AnnotatedTypeMetadata metadata) { if (!ClassUtils.isPresent(WEB_CONTEXT_CLASS, context.getClassLoader())) { return ConditionOutcome.noMatch("web application classes not found"); }/*from w ww . jav a 2 s . c om*/ if (context.getBeanFactory() != null) { String[] scopes = context.getBeanFactory().getRegisteredScopeNames(); if (ObjectUtils.containsElement(scopes, "session")) { return ConditionOutcome.match("found web application 'session' scope"); } } if (context.getEnvironment() instanceof StandardServletEnvironment) { return ConditionOutcome.match("found web application StandardServletEnvironment"); } if (context.getResourceLoader() instanceof WebApplicationContext) { return ConditionOutcome.match("found web application WebApplicationContext"); } return ConditionOutcome.noMatch("not a web application"); }
From source file:org.springframework.boot.autoconfigure.condition.OnResourceCondition.java
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String checking = ConditionLogUtils.getPrefix(logger, metadata); MultiValueMap<String, Object> attributes = metadata .getAllAnnotationAttributes(ConditionalOnResource.class.getName(), true); ResourceLoader loader = context.getResourceLoader() == null ? this.defaultResourceLoader : context.getResourceLoader(); if (attributes != null) { List<String> locations = new ArrayList<String>(); collectValues(locations, attributes.get("resources")); Assert.isTrue(locations.size() > 0, "@ConditionalOnResource annotations must specify at least one resource location"); for (String location : locations) { if (logger.isDebugEnabled()) { logger.debug(checking + "Checking for resource: " + location); }// w ww. ja v a 2 s. c om if (!loader.getResource(location).exists()) { if (logger.isDebugEnabled()) { logger.debug(checking + "Resource not found: " + location + " (search terminated with matches=false)"); } return false; } } } if (logger.isDebugEnabled()) { logger.debug(checking + "Match result is: true"); } return true; }