Core starter providing fundamental building blocks for Spring Boot applications with auto-configuration support, logging, and YAML parsing
—
Spring Boot's intelligent automatic configuration system that provides convention-over-configuration setup based on classpath detection and conditional logic.
Enable and control Spring Boot's auto-configuration mechanism.
/**
* Enable auto-configuration of the Spring Application Context, attempting
* to guess and configure beans that you are likely to need
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface EnableAutoConfiguration {
/**
* Exclude specific auto-configuration classes that should not be applied
* @return the classes to exclude
*/
Class<?>[] exclude() default {};
/**
* Exclude specific auto-configuration class names that should not be applied
* @return the class names to exclude
*/
String[] excludeName() default {};
}
/**
* Indicates that a class provides configuration that can be automatically applied
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface AutoConfiguration {
/**
* Auto-configuration classes that should be applied after this one
* @return the after classes
*/
String[] after() default {};
/**
* Auto-configuration classes that should be applied before this one
* @return the before classes
*/
String[] before() default {};
/**
* Auto-configuration class names that should be applied after this one
* @return the after class names
*/
Class<?>[] afterName() default {};
/**
* Auto-configuration class names that should be applied before this one
* @return the before class names
*/
Class<?>[] beforeName() default {};
}
/**
* Import and apply the specified auto-configuration classes
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface ImportAutoConfiguration {
/**
* The auto-configuration classes that should be imported
* @return the classes to import
*/
Class<?>[] value() default {};
/**
* The auto-configuration classes that should be imported
* @return the classes to import
*/
Class<?>[] classes() default {};
/**
* Exclude specific auto-configuration classes from being imported
* @return the classes to exclude
*/
Class<?>[] exclude() default {};
}Control the order in which auto-configuration classes are applied.
/**
* Hint for that an auto-configuration should be applied after other specified classes
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@interface AutoConfigureAfter {
/**
* The auto-configuration classes that should be applied before this one
* @return the classes that should be applied first
*/
Class<?>[] value() default {};
/**
* The names of the auto-configuration classes that should be applied before this one
* @return the class names that should be applied first
*/
String[] name() default {};
}
/**
* Hint for that an auto-configuration should be applied before other specified classes
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@interface AutoConfigureBefore {
/**
* The auto-configuration classes that should be applied after this one
* @return the classes that should be applied after
*/
Class<?>[] value() default {};
/**
* The names of the auto-configuration classes that should be applied after this one
* @return the class names that should be applied after
*/
String[] name() default {};
}
/**
* Auto-configuration specific variant of Spring's @Order annotation
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface AutoConfigureOrder {
/**
* The order value for this auto-configuration
* @return the order value
*/
int value() default Ordered.LOWEST_PRECEDENCE;
}Conditional annotations that control when auto-configuration classes are applied.
/**
* Conditional that only matches when beans meeting the specified requirements are already present
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface ConditionalOnBean {
/**
* The class types of beans that should be checked
* @return the class types to check
*/
Class<?>[] value() default {};
/**
* The class type names of beans that should be checked
* @return the class type names to check
*/
String[] type() default {};
/**
* The annotation types that should be checked
* @return the annotation types to check
*/
Class<? extends Annotation>[] annotation() default {};
/**
* The names of beans to check
* @return the bean names to check
*/
String[] name() default {};
/**
* Strategy to decide if the application context hierarchy should be considered
* @return the search strategy
*/
SearchStrategy search() default SearchStrategy.ALL;
}
/**
* Conditional that only matches when no beans meeting the specified requirements are already present
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface ConditionalOnMissingBean {
/**
* The class types of beans that should be checked
* @return the class types to check
*/
Class<?>[] value() default {};
/**
* The class type names of beans that should be checked
* @return the class type names to check
*/
String[] type() default {};
/**
* The annotation types that should be checked
* @return the annotation types to check
*/
Class<? extends Annotation>[] annotation() default {};
/**
* The names of beans to check
* @return the bean names to check
*/
String[] name() default {};
/**
* Strategy to decide if the application context hierarchy should be considered
* @return the search strategy
*/
SearchStrategy search() default SearchStrategy.ALL;
/**
* Additional classes that may contain the specified bean types within their generic parameters
* @return the parameterized container classes
*/
Class<?>[] parameterizedContainer() default {};
}/**
* Conditional that only matches when the specified classes are on the classpath
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface ConditionalOnClass {
/**
* The classes that must be present
* @return the classes that must be present
*/
Class<?>[] value() default {};
/**
* The class names that must be present
* @return the class names that must be present
*/
String[] name() default {};
}
/**
* Conditional that only matches when the specified classes are not on the classpath
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface ConditionalOnMissingClass {
/**
* The class names that must not be present
* @return the class names that must not be present
*/
String[] value() default {};
}/**
* Conditional that checks if the specified properties have a specific value
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface ConditionalOnProperty {
/**
* Alias for name()
* @return the property names to check
*/
String[] value() default {};
/**
* A prefix that should be applied to each property
* @return the prefix to apply
*/
String prefix() default "";
/**
* The name of the properties to test
* @return the property names to test
*/
String[] name() default {};
/**
* The string representation of the expected value for the properties
* @return the expected value
*/
String havingValue() default "";
/**
* Specify if the condition should match if the property is not set
* @return whether to match if missing
*/
boolean matchIfMissing() default false;
}/**
* Conditional that only matches when the application is a web application
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface ConditionalOnWebApplication {
/**
* The required type of the web application
* @return the required web application type
*/
Type type() default Type.ANY;
/**
* Available application types
*/
enum Type {
/**
* Any web application will match
*/
ANY,
/**
* Only servlet-based web applications will match
*/
SERVLET,
/**
* Only reactive web applications will match
*/
REACTIVE
}
}
/**
* Conditional that only matches when the application is not a web application
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface ConditionalOnNotWebApplication {
}
/**
* Conditional that matches based on the JVM version the application is running on
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface ConditionalOnJava {
/**
* Configures the comparison with the specified Java version
* @return the comparison range
*/
Range range() default Range.EQUAL_OR_NEWER;
/**
* The Java version to check for
* @return the java version
*/
JavaVersion value();
/**
* Range options for Java version checks
*/
enum Range {
/**
* Equal to, or newer than the specified version
*/
EQUAL_OR_NEWER,
/**
* Older than the specified version
*/
OLDER_THAN
}
}
/**
* Conditional that only matches when the specified resources are on the classpath
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface ConditionalOnResource {
/**
* The resources that must be present
* @return the resources that must be present
*/
String[] resources() default {};
}Manage packages for auto-configuration scanning.
/**
* Indicates that the package containing the annotated class should be registered with AutoConfigurationPackages
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface AutoConfigurationPackage {
/**
* Base packages to scan
* @return the base packages
*/
String[] basePackages() default {};
/**
* Base package classes to scan
* @return the base package classes
*/
Class<?>[] basePackageClasses() default {};
}
/**
* Class for storing auto-configuration packages for reference later
*/
public abstract class AutoConfigurationPackages {
/**
* Return the auto-configuration base packages for the given bean factory
* @param beanFactory the source bean factory
* @return a list of auto-configuration packages
*/
public static List<String> get(BeanFactory beanFactory);
/**
* Determine if auto-configuration base packages are available for the given bean factory
* @param beanFactory the source bean factory
* @return true if packages are available
*/
public static boolean has(BeanFactory beanFactory);
/**
* Register the specified auto-configuration package names
* @param registry the source registry
* @param packageNames the package names to register
*/
public static void register(BeanDefinitionRegistry registry, String... packageNames);
}Usage Examples:
// Basic auto-configuration class
@AutoConfiguration
@ConditionalOnClass(DataSource.class)
@ConditionalOnMissingBean(DataSource.class)
@EnableConfigurationProperties(DataSourceProperties.class)
public class DataSourceAutoConfiguration {
@Bean
@ConditionalOnProperty(prefix = "spring.datasource", name = "url")
public DataSource dataSource(DataSourceProperties properties) {
return DataSourceBuilder.create()
.url(properties.getUrl())
.username(properties.getUsername())
.password(properties.getPassword())
.build();
}
}
// Conditional configuration based on properties
@Configuration
@ConditionalOnProperty(
prefix = "app.feature",
name = "enabled",
havingValue = "true",
matchIfMissing = false
)
public class FeatureConfiguration {
@Bean
@ConditionalOnMissingBean
public FeatureService featureService() {
return new DefaultFeatureService();
}
}
// Web application conditional configuration
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConditionalOnClass(DispatcherServlet.class)
public class WebMvcAutoConfiguration {
@Bean
@ConditionalOnMissingBean(ViewResolver.class)
public InternalResourceViewResolver viewResolver() {
return new InternalResourceViewResolver();
}
}Install with Tessl CLI
npx tessl i tessl/maven-org-springframework-boot--spring-boot-starter