我正在尝试实现 Spring Conditionorg.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?
也许 spring 不知道该文件?
这可以在带注释的类上修复,其中@Value("${swagger.scanner.can.run}")
用来 :
@PropertySource(value="classpath:config.properties")
Regards,
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)