【发布时间】:2015-12-23 18:06:14
【问题描述】:
我正在尝试如下实现 Spring Condition org.springframework.context.annotation.Condition:
public class APIScanningDecisionMaker implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
// Not able to read the property "swagger.scanner.can.run". It is always NULL.
String canRunFlagInStr = context.getEnvironment().getProperty("swagger.scanner.can.run");
// Ignore the rest of the code.
}
}
但是,如上面的代码所示,当我读取属性“swagger.scanner.can.run”时,它始终为 NULL。在我的属性文件中,我将其设置为“swagger.scanner.can.run=false”。
我也尝试使用@Value("${swagger.scanner.can.run}"),但即使这样也返回NULL。当我在这个方法中进行调试时,我可以看到它正在被调用。
为了完成我使用APIScanningDecisionMaker如下:
@Configuration
@EnableSwagger
@Conditional(APIScanningDecisionMaker.class)
public class CustomSwaggerConfig {
// Ignore the rest of the code
}
“swagger.scanner.can.run”被检索为 NULL 有什么原因吗?
【问题讨论】:
标签: java spring spring-mvc