AutoConfiguration class
Marks a class of a library (a "starter") whose @Bean methods give
applications default beans, unless an application declares its own.
A library that wants to add beans to every application using it (a
cache, an HTTP client, a log setup) writes them as @Bean methods of
an @AutoConfiguration class, usually guarded by conditions such as
@ConditionalOnMissingBean(). Its module is registered after the
application's own beans, so the application can replace any of them
by declaring its own bean. Applications themselves use
@Configuration().
Its @Bean methods are not intercepted (proxyBeanMethods: false):
a method that needs another bean takes it as a parameter rather than
calling the other method.
// lib/src/cache.dart of the starter `neon_cache`
@AutoConfiguration()
class CacheAutoConfiguration {
@Bean()
@ConditionalOnMissingBean() // the application's own Cache wins
Cache cache(@Value(r'${neon.cache.size:100}') int size) =>
InMemoryCache(size);
}
The module that holds the class is marked with AutoConfigurationModule.
Spring (Java):
@AutoConfiguration
public class CacheAutoConfiguration {
@Bean @ConditionalOnMissingBean
Cache cache(@Value("${neon.cache.size:100}") int size) {
return new InMemoryCache(size);
}
}
- Inheritance
-
- Object
- Component
- Configuration
- AutoConfiguration
Constructors
- AutoConfiguration([String? name])
-
Marks an auto-configuration class;
namesets its bean name instead of the one derived from the class.const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String?
-
The bean name;
nullgives the class name in lowerCamelCase.finalinherited - proxyBeanMethods → bool
-
Whether a generated subclass makes
@Beanmethods return the container's beans (defaulttrue). Withfalsethe methods are called as written, which avoids the subclass and its restrictions.finalinherited - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited