5

I've read that I should not open an issue on github so I ask here. I've digged into the code and for example spring-boot-actuator-autoconfigure doesn't define the @Configuration\@AutoConfiguration classes inside META-INF/spring.factories follow the content of the file:

org.springframework.boot.diagnostics.FailureAnalyzer=\
org.springframework.boot.actuate.autoconfigure.metrics.ValidationFailureAnalyzer

I've checked and ValidationFailureAnalyzer is not even annotated with @Configuration\@AutoConfiguration. Then I see the file META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports declaring all the classes @AutoConfiguration follow a little extraction of the file:

org.springframework.boot.actuate.autoconfigure.amqp.RabbitHealthContributorAutoConfiguration
org.springframework.boot.actuate.autoconfigure.audit.AuditAutoConfiguration
org.springframework.boot.actuate.autoconfigure.audit.AuditEventsEndpointAutoConfiguration
org.springframework.boot.actuate.autoconfigure.availability.AvailabilityHealthContributorAutoConfiguration
...

all these classes are annotated with @AutoConfiguration. So far so good If we read the docs they say that:

Spring Boot checks for the presence of a META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports file within your published jar.

Indeed if we import:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>2.7.3</version>
</dependency>

everything works just fine. I'm not skilled with gradle but I don't see any special dependecy in spring-boot-actuator-starter or spring-boot-actuator-autoconfigure. Searching on google I've found a discussion here where they say:

In Spring Boot v. 2.7 auto-configuration registration is moved from spring.factories to a new file named META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. Each line contains the fully qualified name of the auto-configuration. For backwards compatibility, entries in spring.factories will still be honored.

But honestly I've tryed to move the configuration classes in the new file but the configuration class is not loaded. I've writed an example here. My org.springframework.boot.autoconfigure.AutoConfiguration.imports file:

com.example.springbootstarterexample.configuration.Config

If I move to the old configuration spring.factries everything works fine.

My @AutoConfiguration class:

@AutoConfiguration(after = JpaRepositoriesAutoConfiguration.class)
//@AutoConfigureAfter(JpaRepositoriesAutoConfiguration.class)
@EnableJpaRepositories(basePackages = "com.example.springbootstarterexample.repository")
@Import({SomeServiceImpl.class, SomeEntityController.class})
public class ExampleAutoConfiguration {

} 

am I doing something wrong? why the spring-boot-starter-actuator works and my spring-boot-starter-example dosn't?

Pp88
  • 830
  • 6
  • 19
  • I'm also searching for info on it to start some tests. Assure you didn't forget to put the `@AutoConfiguration` annotation on the top-level of your auto-configuration classes as mentioned [here](https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.7.0-M2-Release-Notes). I think that this is mandatory for the new imports file to work. – Iogui Aug 26 '22 at 02:12
  • I’ve tryed everything. `@Configuration\@AutoConfoguration` , copiy the dependency in the pom of `spring-boot-starter-actuator/auto configure`, refactor the package of the configuration class with autoconfiguration in it. Nothing worked – Pp88 Aug 26 '22 at 06:40
  • Tryed also to remove all annotation from `ExampleAutoConfiguration` leaving only `@AutoCOnfiguration` and declaring a single bean, still the configuration is not loaded – Pp88 Aug 26 '22 at 09:28
  • I have made some tests yesterday and I was able to make it work. I will provide a sample in a github public repository but I am using kotlin with gradle and not java with maven. – Iogui Aug 27 '22 at 16:01

1 Answers1

4

Your file is called org.springframework.boot.autoconfigure.AutoConfiguration.import,

and must be org.springframework.boot.autoconfigure.AutoConfiguration.imports (notice the extra s) at the end.

Eugene
  • 117,005
  • 15
  • 201
  • 306
  • 1
    I’ve not access to my laptop right now. After I test I will accept don’t worry. I’m not that kind of users… – Pp88 Aug 30 '22 at 06:33
  • Anyway was you able to setup a starter with entities in it? I’ve tryed to load entities in the starter with `@Import` But it doesn’t work. The only way is to use `@EntityScan` in the consumer because if also in the consumer we have entities we declare all the packages of the entities. But this breaks the autoconfiguration meaning. If it’s off tipici I will ask another question. I wonder how `spring-boot-batch-starter` Works, because it uses some tables in order to make the batch work – Pp88 Aug 30 '22 at 06:40
  • 1
    @Pp88 I did not start that project, no, just skimmed over it... you can ask a separate question and I'l take a look – Eugene Aug 30 '22 at 07:00
  • the [question](https://stackoverflow.com/questions/73538904/spring-boot-custom-starter-define-entities-in-it-without-using-entityscan-is) is here if interested @Eugene – Pp88 Aug 30 '22 at 07:53
  • that's important to mention that format is different now, here is an example https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports – Artem Ptushkin May 24 '23 at 09:24