With spring-boot 3.0.1 configuration property and component beans are not created when used as a library in another project. So in library project:
@ConfigurationProperties(prefix = "commons.time.formats")
@Getter
@Setter
public class TimeFormatConf {
private String dynamicZone;
private String timeFormat;
private String dateFormat;
private String dateTimeFormat;
}
@Component
public class DateTimeConfigurer {
private final Logger logger = LoggerFactory.getLogger(DateTimeConfigurer.class);
private final TimeFormatConf timeFormatConf;
public DateTimeConfigurer(TimeFormatConf timeFormatConf) {
this.timeFormatConf = timeFormatConf;
logger.info("Setting up time configuration");
}
@EventListener(ApplicationReadyEvent.class)
public void configureTimeFormat() {
TimeZone.setDefault(TimeZone.getTimeZone(timeFormatConf.getDynamicZone()));
System.setProperty("user.timezone", timeFormatConf.getDynamicZone());
}
}
@Configuration
@ComponentScan
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
@ConfigurationPropertiesScan
public class TimeFormatConfigurer {
}
And spring.factories (src/main/resources/META-INF/spring.factories):
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
[package].TimeFormatConfigurer,\
...
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.
Also, constructor logs from DateTimeConfigurer were not logged.
Exactly the same configuration works fine with version 2.7.7. The plugins used with gradle:
id 'org.springframework.boot' version '3.0.1'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.graalvm.buildtools.native' version '0.9.18'
id 'java'
As well as maven-publish in library project.
Comment From: wilkinsona
This is covered in the migration guide.
Comment From: HattoriHenzo
I already face this issue. Redirect your autoconfiguration in the file: resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports