7

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?

4
  • 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. I think that this is mandatory for the new imports file to work. Commented Aug 26, 2022 at 2: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 Commented Aug 26, 2022 at 6:40
  • Tryed also to remove all annotation from ExampleAutoConfiguration leaving only @AutoCOnfiguration and declaring a single bean, still the configuration is not loaded Commented Aug 26, 2022 at 9: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. Commented Aug 27, 2022 at 16:01

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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…
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 I did not start that project, no, just skimmed over it... you can ask a separate question and I'l take a look
the question is here if interested @Eugene
that's important to mention that format is different now, here is an example github.com/spring-projects/spring-boot/blob/main/…
1

Put the file org.springframework.boot.autoconfigure.AutoConfiguration.imports under resource/META-INF/spring package-> ~ProjectName/src/main/resources/META-INF/spring/

This file then can contain your custom configuration file fully qualified name like example below com.test.autoconfigure.MongoApplicationDBConfig

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.