Spring boot is not a new version spring framework, but a cover layer residing on the spring framework techniques. Before it, although Spring can do a lot for developers, it requires a lot.
The purpose of boot is to release developer from doing trivial, for instance, a lot of XML, annotation configurations and dependency setups. Thus, developers may focus on implementing Java code and business logic.
Developer focus on coding functionalities rather than configuring spring framework. SpringBoot auto-configuration may consider what dependencies in the classpath, via which to infer what needs to be configured. It is very impressive as developing with SpringBoot for it added two ways of development automation, i.e. starter dependencies and automatic configurations. Consequently, it is pretty fast to build up a web application now.
Instead of auto-configuration, what if you want to configure SpringBoot differently? SpringBoot allows overriding auto-configuration as needed to achieve the goals of your applications.
Conditional loading:
- @ConditionalOnClass
- @ConditionalOnBean
- @COnditonalOnProperty
- @ConditonalOnMissingBean
Properties based:
Properties are also a big part of the default configuration for Spring Boot.
- Preconfigured "default" properties for AutoConfiguration classes.
- @EnableConfigurationProperties specifies the default property set.
- Properties can always be overridden
Additional conditionals:
Application type based
Resource (or file) based
Expression based
Configuring Spring boot
Property-based configurations: it is the common way
applcation.properties and application.yml
- Environment variables. (runtime environment)
- Command-line injections
- Cloud configurations(config server,valut,consul)
Bean configuration:
- Adding beans to the default application class??
- Adding beans to separate configuration classes.
- Importing XML-based configurations.
- Component scanning
No comments:
Post a Comment