I am upgrading an application from Spring Boot 2.6 to 3.1. The application is a modular gradle project and makes use of Spring's autoconfiguration.
There is an application that has dependencies to several modules, all these modules provide their own autoconfiguration via a META-INF/spring.factories class. They point to a configuration class that will initialize the code from that module and setup a respective component scan.
That's been working quite well in Spring Boot 2. As the Update Manual suggests, I have migrated these files to META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports and inserted the individual configurations one per line. The Configuration Class itself is annotated as AutoConfiguration and the Main class has @ImportAutoConfiguration.
However, when I start the application, the Autoconfiguration does not seem to be picked up and I get startup errors about missing beans. I verified 10 times that it's the right filename and referencing to the right classes.
Example cases:
main method in an admin-panel module:
package de.herakles.platform.krakenadminpanel;
// import
@SpringBootApplication
@EnableWebMvc
@ImportAutoConfiguration
public class KrakenAdminPanel {
public static void main(String[] args) {
SpringApplication.run(KrakenAdminPanel.class, args);
}
}
there's a gradle dependency on a module called platform-dialect which contains a bean of type SupplierService.
in the module platform-dialect I have this file: platform-dialect/src/main/resources/META-INF/spring /org.springframework.boot.autoconfigure.AutoConfiguration.imports
containing exactly this line:
de.herakles.platform.kraken.platformdialect.KrakenPlatformDialectConfiguration
and the configuration class looks like this:
package de.herakles.platform.kraken.platformdialect;
//imports
@AutoConfiguration
@EnableJpaRepositories(basePackages = "de.herakles")
@EntityScan(basePackages = "de.herakles")
@ComponentScan(basePackageClasses = KrakenPlatformDialectConfiguration.class)
public class KrakenPlatformDialectConfiguration {
}
In that module, there's a de.herakles.platform.kraken.platformdialect.supplier.SupplierService that is annotated as @Service and should be picked up by the component scan (it did prior to the upgrade).
However the error message I am getting is:
Parameter 0 of constructor in de.herakles.platform.krakenadminpanel.dataengineering.VariantController required a bean of type 'de.herakles.platform.kraken.platformdialect.supplier.SupplierService' that could not be found.
I am really struggling - tried all suggestions I could find with nothing working. I am also lacking any indication for how to debug the problem further as the documentation and information on the new autoconfiguration system is not very dense. Therefore I would be very thankful for a solution or a hint for how to debug this issue.
Thanks Matthias
The Issue was in the Gradle Build: Although the individual jars contained the new AutoConfiguration.imports file, these jars were not put in the uber jar created by the spring boot plugin - there were still old versions in there without the AutoConfiguration.imports.
Cleaning all build folders solved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With