Quick revision
The short answer
I would build two modules: acme-audit-spring-boot-autoconfigure with the auto-configuration and properties, and a thin acme-audit-spring-boot-starter that depends on it and the audit client library. The auto-configuration class uses @AutoConfiguration, @ConditionalOnClass, @ConditionalOnMissingBean so services can override beans, and @ConditionalOnProperty so they can disable it, with settings bound through @ConfigurationProperties under acme.audit. I would test it with ApplicationContextRunner, using withPropertyValues, withUserConfiguration and FilteredClassLoader.
What to remember
In this answer, we designed an internal audit starter the way Spring Boot builds its own: an autoconfigure module with the code and a thin starter that pulls in dependencies, named acme-audit-spring-boot-starter because the spring-boot-starter prefix is reserved. The auto-configuration uses @AutoConfiguration with class, missing-bean and property conditions, settings bind through @ConfigurationProperties with generated metadata, the class is registered in the AutoConfiguration.imports file, and ApplicationContextRunner tests prove each condition.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would build two modules: acme-audit-spring-boot-autoconfigure with the auto-configuration and properties, and a thin acme-audit-spring-boot-starter that depends on it and the audit client library. The auto-configuration class uses @AutoConfiguration, @ConditionalOnClass, @ConditionalOnMissingBean so services can override beans, and @ConditionalOnProperty so they can disable it, with settings bound through @ConfigurationProperties under acme.audit. I would test it with ApplicationContextRunner, using withPropertyValues, withUserConfiguration and FilteredClassLoader.
Why this question is asked
Once a company has dozens of services, the same audit setup gets copied into each one, with small differences and bugs. A starter turns that copy into a dependency: add one line to the build and auditing just works, with sensible defaults and room to change them. Interviewers ask this because a well-built starter shows that we understand how auto-configuration works from the inside. In this answer, we will design the module layout and naming, write the auto-configuration and properties classes, register them, test them with ApplicationContextRunner, and then cover how to version the starter.
1Designing the Modules and the Name
Spring Boot's own convention is a split into two modules. The autoconfigure module holds the code: the auto-configuration class, the properties class and the registration file. Its dependency on the audit client is optional, so the module can be on a classpath without forcing the client in. The starter module holds no code at all; it is a pom that depends on the autoconfigure module and on the libraries a service needs to actually use the feature.
Naming matters too. The spring-boot-starter-* prefix is reserved for Spring Boot's own starters, so third-party and internal starters put their own name first: acme-audit-spring-boot-starter and acme-audit-spring-boot-autoconfigure. A reader then knows at once that it is ours, and we never clash with a future official starter.
- Servicedepends on acme-audit-spring-boot-starter only
- acme-audit-spring-boot-starterpom only: autoconfigure + audit client + HTTP client
- acme-audit-spring-boot-autoconfigure
AuditAutoConfiguration,AuditProperties, imports file - acme-audit-clientplain Java library, no Spring
4 layers, from the top down. Step through them one at a time.
2Writing the Auto-configuration Class
The auto-configuration class is an ordinary configuration class with conditions. Each condition answers one question about the service it lands in.
@ConditionalOnClass makes the whole class back off if the audit client is not on the classpath, which keeps the autoconfigure module harmless on its own. @ConditionalOnProperty with matchIfMissing = true means auditing is on by default but a service can switch it off with acme.audit.enabled=false, which is useful in tests and local runs. @ConditionalOnMissingBean on each bean means a service that defines its own AuditClient wins, and ours steps aside. Notice that the filter is only created in servlet applications, so a batch job using the starter does not get a web filter.
3Binding Settings With @ConfigurationProperties
Settings live under one dedicated prefix, acme.audit, bound to a typed class. Validation catches mistakes at startup instead of at the first audit event.
We add spring-boot-configuration-processor as an optional annotation processor in the autoconfigure module. It reads the class and its Javadoc comments and generates META-INF/spring-configuration-metadata.json, so IDEs autocomplete acme.audit.* properties with descriptions and defaults. That small step is what makes a starter feel like part of Boot.
4Registering the Auto-configuration
Boot does not find auto-configuration by component scanning, and it must not, because scanning would make the configuration impossible to back off. Instead the autoconfigure module lists it in a registration file.
If the audit filter must come after Boot's own security configuration, @AutoConfiguration(after = SecurityAutoConfiguration.class) sets the order. We keep the package of the auto-configuration out of any package that services might scan, for the same reason.
5Testing With ApplicationContextRunner
Starting a full application for each case would be slow. ApplicationContextRunner starts a tiny context with only the configurations we give it, in milliseconds, and lets us assert on what was created.
Each test proves one condition. withPropertyValues proves the switch, withUserConfiguration proves the override point, and FilteredClassLoader hides a class to prove the starter is harmless without the library. A WebApplicationContextRunner covers the servlet-only filter. Finally, one sample service in the build uses the starter for real, so we also test the published artifacts.
6Follow-up questions
How would you version the starter relative to Spring Boot versions?
I would give it its own semantic version and declare which Boot line each release supports, for example 3.x of the starter for Boot 3.5 and 4.x for Boot 4. The platform BOM pins a compatible starter version for each Boot version, so services never choose the pair themselves. A breaking change in the starter, such as a renamed property, is a major version, with the old property deprecated first.
Why should the audit client dependency be optional in the autoconfigure module?
So that the autoconfigure module can sit on a classpath without dragging the client in, and @ConditionalOnClass decides whether to activate. The starter is the place that says yes, I want the feature, by adding the client as a normal dependency.
What if a service needs two audit clients?
It defines its own AuditClient beans. Because our bean is @ConditionalOnMissingBean, the starter steps aside. The starter's filter also needs a single client, so the service then either marks one as @Primary or defines its own filter.
7Conclusion
In this answer, we designed an internal audit starter the way Spring Boot builds its own: an autoconfigure module with the code and a thin starter that pulls in dependencies, named acme-audit-spring-boot-starter because the spring-boot-starter prefix is reserved. The auto-configuration uses @AutoConfiguration with class, missing-bean and property conditions, settings bind through @ConfigurationProperties with generated metadata, the class is registered in the AutoConfiguration.imports file, and ApplicationContextRunner tests prove each condition.
Open with
I would follow Boot's own layout. An acme-audit-spring-boot-autoconfigure module holds the AuditAutoConfiguration, the AuditProperties class and the AutoConfiguration.imports file, with the audit client as an optional dependency. A thin acme-audit-spring-boot-starter has no code and just depends on the autoconfigure module and the client.
Then, if they want more
I would not name it spring-boot-starter-audit, because that prefix is reserved for Spring Boot. The auto-configuration class is annotated with @AutoConfiguration and @ConditionalOnClass on the audit client, and @ConditionalOnProperty on acme.audit.enabled with matchIfMissing true, so it is on by default but can be turned off.
Every bean is @ConditionalOnMissingBean, so a service can override it, and the request filter is only for servlet apps. Properties bind under the acme.audit prefix with @ConfigurationProperties and validation, and I would add the configuration processor so IDEs get metadata.
For tests I would use ApplicationContextRunner: one test for the default, withPropertyValues for disabling, withUserConfiguration to show a user bean wins, and FilteredClassLoader to show it backs off without the library. For versioning, the starter has its own semantic version mapped to a supported Boot line, and the platform BOM pins the pair.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design an internal starter that configures an audit client for all services. Describe...": https://scrivio-interview-library.netlify.app/spring-boot/auto-configuration/2f3e839872/