I am creating a Maven artifact with following classes and configuration in custom Spring Starter project:
@ConfigurationProperties(prefix = "commons.time.formats")
@Getter
@Setter
public class TimeFormatConf {
... fields
}
@Component
@Configuration
@AllArgsConstructor
@EnableConfigurationProperties(TimeFormatConf.class)
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
public class DateTimeConfigurer {
private final TimeFormatConf timeFormatConf;
@EventListener(ApplicationReadyEvent.class)
public void configureTimeFormat() {
TimeZone.setDefault(TimeZone.getTimeZone(timeFormatConf.getDynamicZone()));
System.setProperty("user.timezone", timeFormatConf.getDynamicZone());
}
}
And spring.factories (src/main/resources/META-INF/spring.factories
):
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
[package].DateTimeConfigurer,\
...
When I try to autowire a TimeFormatConf class my spring application crashes at start up as it cannot find a bean of TimeFormatConf class:
Parameter 0 of constructor in com.some.package.b.Class required a bean of type 'com.some.package.a.TimeFormatConf' that could not be found.
The artifact is present with correct configuration on classpath. So it has to do something with either declaration or configuration of Spring.
I have also tried adding @Component
on properties class and @ComponentScan
on configuration class does not have any effect.
Reverting to Spring Boot 2.7.7 on both projects fixed the problem. So it seems to be a bug or at least lack of documentation. I have opened an issue to follow this up with spring team: https://github.com/spring-projects/spring-boot/issues/33720