Automatic configuration capabilities for Spring applications based on classpath contents and environment properties
npx @tessl/cli install tessl/maven-org-springframework-boot--spring-boot-autoconfigure@3.5.00
# Spring Boot AutoConfigure
1
2
Spring Boot AutoConfigure provides automatic configuration capabilities for Spring applications through conditional bean registration and configuration based on classpath contents, environment properties, and other conditions. It includes auto-configurations for over 50 different technologies and frameworks, enabling "convention over configuration" development with intelligent defaults and extensive customization options.
3
4
## Package Information
5
6
- **Package Name**: spring-boot-autoconfigure
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Group ID**: org.springframework.boot
10
- **Artifact ID**: spring-boot-autoconfigure
11
- **Installation**: Add dependency to your build configuration
12
13
Maven:
14
```xml
15
<dependency>
16
<groupId>org.springframework.boot</groupId>
17
<artifactId>spring-boot-autoconfigure</artifactId>
18
<version>3.5.3</version>
19
</dependency>
20
```
21
22
Gradle:
23
```gradle
24
implementation 'org.springframework.boot:spring-boot-autoconfigure:3.5.3'
25
```
26
27
## Core Imports
28
29
```java
30
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
31
import org.springframework.boot.autoconfigure.SpringBootApplication;
32
import org.springframework.boot.autoconfigure.condition.*;
33
import org.springframework.boot.context.properties.ConfigurationProperties;
34
```
35
36
## Basic Usage
37
38
```java
39
import org.springframework.boot.SpringApplication;
40
import org.springframework.boot.autoconfigure.SpringBootApplication;
41
42
// Primary way to enable auto-configuration
43
@SpringBootApplication
44
public class MyApplication {
45
public static void main(String[] args) {
46
SpringApplication.run(MyApplication.class, args);
47
}
48
}
49
50
// Alternative: explicit auto-configuration enabling
51
@Configuration
52
@EnableAutoConfiguration
53
@ComponentScan
54
public class MyConfiguration {
55
// Configuration beans
56
}
57
```
58
59
## Architecture
60
61
Spring Boot AutoConfigure is built around several key architectural patterns:
62
63
- **Conditional Configuration**: Uses sophisticated `@ConditionalOn*` annotations to determine when configurations should be applied
64
- **Auto-Configuration Classes**: Named `*AutoConfiguration`, these classes define beans and configurations for specific technologies
65
- **Configuration Properties**: `*Properties` classes provide type-safe external configuration binding
66
- **Import Selectors**: Automatically discover and load auto-configuration classes based on classpath contents
67
- **Customization Points**: `*Customizer` interfaces allow fine-grained modification of auto-configurations
68
- **Ordering Control**: `@AutoConfigureBefore` and `@AutoConfigureAfter` manage configuration dependencies
69
70
## Capabilities
71
72
### Core Auto-Configuration
73
74
Primary annotations and classes that form the foundation of Spring Boot's auto-configuration system.
75
76
```java { .api }
77
@Target(ElementType.TYPE)
78
@Retention(RetentionPolicy.RUNTIME)
79
@Documented
80
@Inherited
81
@SpringBootConfiguration
82
@EnableAutoConfiguration
83
@ComponentScan
84
public @interface SpringBootApplication {
85
Class<?>[] exclude() default {};
86
String[] excludeName() default {};
87
String[] scanBasePackages() default {};
88
Class<?>[] scanBasePackageClasses() default {};
89
}
90
91
@Target(ElementType.TYPE)
92
@Retention(RetentionPolicy.RUNTIME)
93
@Documented
94
@Inherited
95
@AutoConfigurationPackage
96
public @interface EnableAutoConfiguration {
97
String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
98
Class<?>[] exclude() default {};
99
String[] excludeName() default {};
100
}
101
```
102
103
[Core Auto-Configuration](./core-autoconfiguration.md)
104
105
### Conditional Configuration
106
107
Comprehensive set of conditional annotations that determine when auto-configurations should be applied based on various runtime conditions.
108
109
```java { .api }
110
@Target({ElementType.TYPE, ElementType.METHOD})
111
@Retention(RetentionPolicy.RUNTIME)
112
@Documented
113
@Conditional(OnClassCondition.class)
114
public @interface ConditionalOnClass {
115
Class<?>[] value() default {};
116
String[] name() default {};
117
}
118
119
@Target({ElementType.TYPE, ElementType.METHOD})
120
@Retention(RetentionPolicy.RUNTIME)
121
@Documented
122
@Conditional(OnBeanCondition.class)
123
public @interface ConditionalOnMissingBean {
124
Class<?>[] value() default {};
125
String[] type() default {};
126
String[] name() default {};
127
}
128
129
@Target({ElementType.TYPE, ElementType.METHOD})
130
@Retention(RetentionPolicy.RUNTIME)
131
@Documented
132
@Conditional(OnPropertyCondition.class)
133
public @interface ConditionalOnProperty {
134
String[] value() default {};
135
String prefix() default "";
136
String[] name() default {};
137
String havingValue() default "";
138
boolean matchIfMissing() default false;
139
}
140
```
141
142
[Conditional Configuration](./conditional-configuration.md)
143
144
### Web Application Configuration
145
146
Auto-configuration for web applications including Spring MVC, WebFlux, embedded servers, and web-related components.
147
148
```java { .api }
149
@AutoConfiguration
150
@ConditionalOnWebApplication(type = Type.SERVLET)
151
@ConditionalOnClass(DispatcherServlet.class)
152
public class DispatcherServletAutoConfiguration {
153
// Configuration for Spring MVC DispatcherServlet
154
}
155
156
@AutoConfiguration
157
@ConditionalOnWebApplication(type = Type.SERVLET)
158
@ConditionalOnClass(ServletRequest.class)
159
public class ServletWebServerFactoryAutoConfiguration {
160
// Configuration for servlet web server factories
161
}
162
163
@AutoConfiguration
164
@ConditionalOnWebApplication(type = Type.REACTIVE)
165
@ConditionalOnClass(WebFluxConfigurer.class)
166
public class WebFluxAutoConfiguration {
167
// Configuration for Spring WebFlux
168
}
169
```
170
171
[Web Configuration](./web-configuration.md)
172
173
### Data Access Configuration
174
175
Comprehensive data access auto-configurations for relational databases, NoSQL systems, and data repositories.
176
177
```java { .api }
178
@AutoConfiguration
179
@ConditionalOnClass({DataSource.class, JdbcTemplate.class})
180
public class DataSourceAutoConfiguration {
181
// DataSource configuration
182
}
183
184
@AutoConfiguration
185
@ConditionalOnClass(JpaRepository.class)
186
@ConditionalOnMissingBean({JpaRepositoryFactoryBean.class, JpaRepositoryConfigExtension.class})
187
public class JpaRepositoriesAutoConfiguration {
188
// JPA repositories configuration
189
}
190
191
@AutoConfiguration
192
@ConditionalOnClass({RedisOperations.class, JedisConnection.class})
193
public class RedisAutoConfiguration {
194
// Redis configuration
195
}
196
```
197
198
[Data Configuration](./data-configuration.md)
199
200
### Security Configuration
201
202
Auto-configuration for Spring Security including servlet security, reactive security, OAuth2, and SAML integration.
203
204
```java { .api }
205
@AutoConfiguration
206
@ConditionalOnClass(SecurityFilterChain.class)
207
@ConditionalOnWebApplication(type = Type.SERVLET)
208
public class SecurityAutoConfiguration {
209
// Spring Security configuration
210
}
211
212
@AutoConfiguration
213
@ConditionalOnClass({OAuth2AuthorizedClient.class, ReactiveOAuth2AuthorizedClientService.class})
214
@ConditionalOnWebApplication(type = Type.REACTIVE)
215
public class ReactiveOAuth2ClientAutoConfiguration {
216
// Reactive OAuth2 client configuration
217
}
218
```
219
220
[Security Configuration](./security-configuration.md)
221
222
### Messaging Configuration
223
224
Auto-configurations for messaging systems including JMS, AMQP (RabbitMQ), Apache Kafka, and Apache Pulsar.
225
226
```java { .api }
227
@AutoConfiguration
228
@ConditionalOnClass({Message.class, JmsTemplate.class})
229
public class JmsAutoConfiguration {
230
// JMS configuration
231
}
232
233
@AutoConfiguration
234
@ConditionalOnClass({RabbitTemplate.class, Channel.class})
235
public class RabbitAutoConfiguration {
236
// RabbitMQ configuration
237
}
238
239
@AutoConfiguration
240
@ConditionalOnClass(KafkaTemplate.class)
241
public class KafkaAutoConfiguration {
242
// Apache Kafka configuration
243
}
244
```
245
246
[Messaging Configuration](./messaging-configuration.md)
247
248
### Template Engine Configuration
249
250
Auto-configurations for template engines including Thymeleaf, FreeMarker, Mustache, and Groovy templates.
251
252
```java { .api }
253
@AutoConfiguration
254
@ConditionalOnClass({TemplateMode.class, SpringTemplateEngine.class})
255
public class ThymeleafAutoConfiguration {
256
// Thymeleaf template engine configuration
257
}
258
259
@AutoConfiguration
260
@ConditionalOnClass({freemarker.template.Configuration.class, FreeMarkerConfigurationFactory.class})
261
public class FreeMarkerAutoConfiguration {
262
// FreeMarker template engine configuration
263
}
264
```
265
266
[Template Engine Configuration](./template-configuration.md)
267
268
### JSON Processing Configuration
269
270
Auto-configurations for JSON processing libraries including Jackson, Gson, and JSON-B.
271
272
```java { .api }
273
@AutoConfiguration
274
@ConditionalOnClass(ObjectMapper.class)
275
public class JacksonAutoConfiguration {
276
// Jackson JSON processing configuration
277
}
278
279
@AutoConfiguration
280
@ConditionalOnClass(Gson.class)
281
public class GsonAutoConfiguration {
282
// Google Gson configuration
283
}
284
```
285
286
[JSON Processing Configuration](./json-configuration.md)
287
288
### Cache Configuration
289
290
Auto-configurations for caching providers including Redis, Caffeine, EhCache, and Hazelcast.
291
292
```java { .api }
293
@AutoConfiguration
294
@ConditionalOnClass(CacheManager.class)
295
@ConditionalOnBean(CacheAspectSupport.class)
296
public class CacheAutoConfiguration {
297
// Cache abstraction configuration
298
}
299
300
@AutoConfiguration
301
@ConditionalOnClass({RedisOperations.class, RedisCacheManager.class})
302
public class RedisCacheConfiguration {
303
// Redis cache configuration
304
}
305
```
306
307
[Cache Configuration](./cache-configuration.md)
308
309
### Service Connection API
310
311
Standardized API for defining and accessing connection details for external services including databases, messaging systems, and caching providers.
312
313
```java { .api }
314
/**
315
* Base interface for types that provide connection details to remote services
316
*/
317
public interface ConnectionDetails {
318
// Marker interface - specific implementations provide actual connection details
319
}
320
321
/**
322
* Factory to create ConnectionDetails from a given source
323
*/
324
public interface ConnectionDetailsFactory<S, D extends ConnectionDetails> {
325
D getConnectionDetails(S source);
326
}
327
328
/**
329
* Details required to establish a connection to a JDBC database
330
*/
331
public interface JdbcConnectionDetails extends ConnectionDetails {
332
String getJdbcUrl();
333
default String getUsername() { return null; }
334
default String getPassword() { return null; }
335
default String getDriverClassName() { return null; }
336
}
337
```
338
339
[Service Connections](./service-connections.md)
340
341
## Types
342
343
### Core Configuration Types
344
345
```java { .api }
346
public class AutoConfigurationPackages {
347
public static List<String> get(BeanFactory beanFactory);
348
public static void register(BeanDefinitionRegistry registry, String... packageNames);
349
}
350
351
public final class AutoConfigurations extends Configurations {
352
public static AutoConfigurations of(Class<?>... classes);
353
}
354
355
public interface AutoConfigurationMetadata {
356
boolean wasProcessed(String className);
357
Integer getInteger(String className, String key);
358
Integer getInteger(String className, String key, Integer defaultValue);
359
Set<String> getSet(String className, String key);
360
Set<String> getSet(String className, String key, Set<String> defaultValue);
361
String get(String className, String key);
362
String get(String className, String key, String defaultValue);
363
}
364
```
365
366
### Condition Types
367
368
```java { .api }
369
public enum SearchStrategy {
370
CURRENT, ANCESTORS, ALL
371
}
372
373
public final class ConditionMessage {
374
public static ConditionMessage empty();
375
public static ConditionMessage of(String message, Object... args);
376
public ConditionMessage andCondition(String condition, Object... args);
377
public ConditionMessage because(String reason, Object... args);
378
}
379
380
public class ConditionOutcome {
381
public ConditionOutcome(boolean match, String message);
382
public ConditionOutcome(boolean match, ConditionMessage message);
383
public boolean isMatch();
384
public String getMessage();
385
}
386
```