Last active
June 20, 2019 06:05
-
-
Save linxiaobai/29c54dd7c30daf863522aefd89cc0a55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class Condition implements ConfigurationCondition { | |
@Override | |
public ConfigurationPhase getConfigurationPhase() { | |
return ConfigurationPhase.PARSE_CONFIGURATION; | |
} | |
//condition获取properties,直接用context.getEnvironment().getProperty()不行,因为配置还未加载进去,所以需要用以下写法 | |
@Override | |
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { | |
Properties properties=new Properties(); | |
Resource resource = context.getResourceLoader().getResource("classpath:/batch.properties"); | |
try { | |
properties.load(resource.getInputStream()); | |
final String enable = properties.getProperty("batch.enable"); | |
if(enable == null) { | |
return false; | |
} | |
return Boolean.valueOf(enable.trim()); | |
} catch (Exception e) { | |
logger.error("Exception occurred while batch configuration" , e); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment