I'm using Springdoc 1.4 with Spring-Boot 2.3 and in the OperationCustomizer class, I need to read value from the application properties file. But everytime the field is always initialized to null
. The specifications are as follows
application.properties
application.security.authorization=true
OperationCustomizer class
@Component
public class GlobalHeaderAdder implements OperationCustomizer {
@Value("${application.security.authorization:true}")
Boolean authFilterEnabled; // <---- Initialized to NULL
@Override
public Operation customize(Operation operation, HandlerMethod handlerMethod) {
System.out.println("____________________________\n" + authFilterEnabled + "\n+++++++++++++++++++++++++");
if (authFilterEnabled) {
operation.addParametersItem(new Parameter().$ref("#/components/parameters/ClientID"));
}
operation.addSecurityItem(new SecurityRequirement().addList("Authorization"));
List<Parameter> parameterList = operation.getParameters();
if (parameterList != null && !parameterList.isEmpty()) {
Collections.rotate(parameterList, 1);
}
return operation;
}
}
The class is being called by the below code
@Bean
public GroupedOpenApi hideApis() {
return GroupedOpenApi.builder().group("default")
.pathsToExclude("/api/v2/**", "/v2/**")
.pathsToMatch("/api/v1/**", "/v1/**")
.addOperationCustomizer(new GlobalHeaderAdder())
.build();
}
The approach provided here works but I would like to have an approach where I don't have to make the field static.