Spring Boot 2.0 Autoconfiguration
Spring Boot 2.0 Autoconfiguration
0
Spring Boot makes it easy to create standalone, production-grade Spring based
applications that you can just run.
Spring boot plugin
The main feature of the build plugins is that they’re able to package the project as an
executable uber-JAR. This includes packing all of the application’s dependencies within the
JAR and adding a manifest to the JAR with entries that make it possible to run the
application with java -jar.
Spring Boot addresses project dependency complexity by providing several dozen “starter”
dependencies. A starter dependency is essentially a Maven POM that defines transitive
dependencies on other libraries that together provide support for some functionality. Many
of these starter dependencies are named to indicate the facet or kind of functionality they
provide.
Spring boot plugin
Using automatic configuration In a nutshell, Spring Boot auto-configuration is a runtime
(more accurately, application startup-time) process that considers several factors to decide
what Spring configuration should and should not be applied. To illustrate, here are a few
examples of the kinds of things that Spring Boot auto-configuration might consider:
■ Is Spring’s JdbcTemplate available on the classpath? If so and if there is a Data-Source
bean, then auto-configure a JdbcTemplate bean.
■ Is Thymeleaf on the classpath? If so, then configure a Thymeleaf template resolver, view
resolver, and template engine.
■ Is Spring Security on the classpath? If so, then configure a very basic web security setup.
Spring boot plugin
What makes all of this configuration special, however, is that it leverages Spring’s support
for conditional configuration, which was introduced in Spring 4.0. Conditional configuration
allows for configuration to be available in an application, but to be ignored unless certain
conditions are met.
Because H2 is on the classpath, an embedded H2 database bean will be created.This bean
is of type javax.sql.DataSource, which the JPA implementation(Hibernate) will need to
access the database.
What Does @SpringBootApplication Do?
@Configuration is used to turn a class into a JavaConfig source so you can define beans in
it, etc. The class used in SpringApplication.run() should be a configuration class (though
XML configs are possible).
@EnableAutoConfiguration attempts to guess and configure beans that you are likely to
need based on our code and class-path. if Tomcat is present due to web dependencies in
the POM, it will set it up and use it for you.
@ComponentScan is used to tell Spring to automatically search for and wire up classes
based on their annotations (e.g. make @Controllers register themselves, populate @Value
variables, etc.)
What are spring starters?
The starters are just maven projects that include the required dependencies for
the module to work properly. In maven, all the dependencies of the
dependencies you define in your project are part of your project’s dependencies.
The command below prints all the dependencies of the project in the form of a
tree.
What are spring starters?
The starters are just maven projects that include the required dependencies for
the module to work properly. In maven, all the dependencies of the
dependencies you define in your project are part of your project’s dependencies.
The command below prints all the dependencies of the project in the form of a
tree.
Mvn dependecy:tree