Overall, this class sets up configurations for formatting date and time types, adding authentication headers, and defining the logging level for the Feign client used in the organization structure client. The internalKey property is a key component for authentication.
What do you think about this class with @Bean and @Value inside, but without any stereotype annotation, such a @Component or @Configuration?
public class OrgClientConfig {
protected final org.slf4j.Logger log = LoggerFactory.getLogger(this.getClass());
@Value("${aut.internalKey}")
private String internalKey;
@Bean
public FeignFormatterRegistrar localDateFeignFormatterRegistrar() {
return formatterRegistry -> {
// just handling JSR-310 specific date and time types
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
registrar.registerFormatters(formatterRegistry);
// handles Joda-specific types as well as Date, Calendar, Long
JodaTimeFormatterRegistrar jodaRegister = new JodaTimeFormatterRegistrar();
jodaRegister.setUseIsoFormat(true);
jodaRegister.registerFormatters(formatterRegistry);
// regular DateFormat-based Date, Calendar, Long converters
new DateFormatterRegistrar().registerFormatters(formatterRegistry);
// custom formatters
formatterRegistry.addFormatter(new DateFormatter());
};
}
@Bean
public RequestInterceptor basicAuthRequestInterceptor() {
return new InternalKeyRequestInterceptor(internalKey);
}
@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}
I think this class is useless in fact. It settles in separate library.
The library does not have any resource folder.
Now I am rewriting the code to Java 17 from Java 8, from Spring boot 1xx to Spring boot 3xxx.
And in new version of the class I started to get error that internalKey is null, which was not problem for Java8.Why do they use @Value, if there is no any properties file there?
Why do they use @Bean without @Component or @Configuration above the class?
Do you find this as incorrect code?