Spring Boot

What is Spring Boot?
Spring Boot makes it easy to create stand-alone,
production-grade Spring based Applications that you can "just run".
- Building an end to end app
- Spring Boot Features
- Configuration and Customization
What is Spring?
- Application frameworks
- Programming and configuration model
- Infrastructure support
Problems with Spring
- Huge framework
- Multiple setup steps
- Multiple configuration steps
- Multiple build and deploy steps
What Spring Boot give us
- Opinionated
- Convention over Configuration
- Stand alone
- Production ready
Java dependencies-Maven
Maven is a build automation
tool used primarily for Java projects. The word maven means "accumulator
of knowledge" in Yiddish.
Maven addresses two aspects of building
software:
- it describes how software is built
- it describes its dependencies.
Maven takes care of
- Dependency Management
- Building a deployable unit - Packaging War Ear
- Running things you want - like unit tests
- Multiple Modules
- Running application in Tomcat
- Generating sample projects. Maven Archetypes archetype:generate
Project Object Model (pom.xml) :
POM stands for "Project Object Model".
It is an XML representation of a Maven project held in a file named pom.xml.
The POM contains information about the project
and various configuration detail used by Maven to build the project(s).
All POM files require the project element and
three mandatory fields: groupId, artifactId, version.
Root
element of POM.xml is project and it has major sub-nodes :
- project: It is the root element of project
- modelVersion: It is the sub element of project. It specifies the modelVersion. It should be set to 4.0.0.
- groupId: It is the sub element of project. It specifies the id for the project group.
- artifactId: It is the sub element of project. It specifies the id for the artifact (project). An artifact is something that is either produced or used by a project. Examples of artifacts produced by Maven for a project include: JARs, source and binary distributions, and WARs.
- version: It is the sub element of project. It specifies the version of the artifact under given group.
Creating a Maven Java
Project
Update
the pom.xml file
Building
Spring Boot Application
Starting
Sprint Boot
- Sets up default configuration
- Starts Spring application context
- Performs class path scan
- Starts Tomcat server
Add a
controller
- A Java class
- Marked with annotations
- Has info about
- What URL access triggers it?
- What method to run when accessed?
Embedded
Tomcat Server
- Convenience
- Servlet container config is now application config
- Standalone application
- Useful for microservices architecture
REST API
- GET /topics gets all topics
- GET /topics/id gets the topic
- POST /topics create new topic
- PUT /topics/id updates the topic
- DELETE /topics/id deletes the topic
Creating a
Business Service