Spring Boot is a framework for creating stand-alone, production-grade Spring based applications that can be "just run". It aims to provide a radically faster and widely accessible starting experience for developing Spring applications. Spring Boot applications can be started using java -jar or traditional WAR deployments and require very little Spring configuration. The document then discusses system requirements, development environment, creating a simple Hello World application, using Spring Boot Admin to monitor applications, configuring databases, Spring Data JPA, REST controllers, caching with EhCache, building web applications with Thymeleaf, and project structure.
Introduction to Spring Boot by Hongseong Jeon emphasizing its ease of creating applications.
Overview of Spring Boot's capabilities for creating standalone applications, configuration needs, and its development goals.
Requirements for Spring Boot 1.4.0 including Java version and servlet container compatibility.
Necessary build tools like Maven and Gradle, and IDEs like Eclipse to support Spring Boot development.
Steps to create a simple Spring Boot application including a main class and controller setup.
Instructions on how to run the simple application and access it via a local server.
Introduction to Spring Boot Admin for managing and monitoring Spring Boot applications.
Creating a Spring Boot Admin application with dependency configurations and basic server setup.
Adding client dependencies and configuring properties to connect with Spring Boot Admin.
Testing the Spring Boot application and accessing the dashboard for monitoring.
Various features of Spring Boot Admin including Application Details, Environment, Logging, and Health metrics.Configuring H2 as an embedded database in Spring Boot with properties for connections and web console.
Utilizing Spring Boot Admin for monitoring the configured H2 database.
Using Spring Data JPA for repository pattern implementation and verifying loaded data.
Defining a RESTful service interface and controller for managing city resources.
Integrating Ehcache into Spring Boot, including configuration and testing performance.
Using Thymeleaf for web applications, compiling HTML with Spring Boot, and API monitoring.
Outline of project package structure and resources for a Spring Boot application.
List of references for further learning about Spring Boot and related tools.
Open floor for audience questions regarding the Spring Boot presentation.
INTRODUCING SPRING BOOT
Easy to create stand-alone, production-grade Spring based
applications that you can “just run”.
It needs very little spring configuration.
Create Java applications that can be started using java –jar or
more traditional war deployments.
Primary goals for the Spring Boot.
Provide a radically faster and widely accessible getting started
experience for all Spring development.
Be opinionated out of the box, but get out of the way quickly as
requirements start to diverge from the defaults.
Provide a range of non-functional features that are common to
large classes of projects (e.g.embedded servers, security,
metrics, health checks, externalized configuration).
Absolutely no code generation and no requirement for XML
configuration.
3.
SYSTEM REQUIREMENTS
SpringBoot 1.4.0 requires Java 7 and Spring Framework 4.1.5
or above.
Servlet containers
Servlet 3.0+ compatible container
4.
DEVELOPMENT ENVIRONMENT
Buildtool that supports dependency management
Maven – maven.apache.org
Gradle – www.gradle.org
Development IDE
Eclipse or Any Editor
Eclipse plugin
- m2ecipse
- gradle
SPRING BOOT ADMIN
Spring Boot Admin is a simple application to manage and
monitor your Spring Boot Applications.
The applications register with our Spring Boot Admin Client
(via http) or are discovered using Spring Cloud (e.g. Eureka).
9.
SPRING BOOT ADMINAPPLICATION
Create New Gradle Project
Add spring boot server libraries to project dependencies.
Create SpringBootAdminApplication
dependencies {
compile 'de.codecentric:spring-boot-admin-server:1.3.2'
compile 'de.codecentric:spring-boot-admin-server-ui:1.3.2'
compile 'org.springframework.boot:spring-boot-starter-web:1.3.1.RELEASE'
}
DATABASE CONFIGURATION
H2Database
H2 is written in Java and is easily runs as an embedded in-
memory database.
Because it is an embedded in memory database, it makes your
build portable.
H2 Database and Spring Boot
By adding this dependency to your gradle, Sring Boot will
automatically configure the H2 database.
JDBC DataSource Configuration in the application.properties.
dependencies {
compile 'com.h2database:h2'
}
spring.datasource.jndi-name=java:jboss/datasources/customers
23.
DATABASE CONFIGURATION
JDBCDataSource Configuration in the application.properties
# ===============================
# = DATA SOURCE
# ===============================
# Set here configurations for the database connection
spring.datasource.url = jdbc:h2:d:/applications/springBoot/data/boot.db
# JDBC Driver class
spring.datasource.driver-class-name=org.h2.Driver
# Username and password
spring.datasource.username = sa
spring.datasource.password = sa
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# Number of ms to wait before throwing an exception if no connection is available.
spring.datasource.max-wait=10000
# Maximum number of active connections that can be allocated from this pool at the same
time.
spring.datasource.max-active=50
# Validate the connection before borrowing it from the pool.
spring.datasource.test-on-borrow=true
24.
DATABASE CONFIGURATION
H2Database Web Console
Enable H2 Database Web Console in the application.properties
H2 Database Web Console : http://${serviceUrl}/h2-console/
# Enable H2 Database Web Console
spring.h2.console.enabled=true
SPRING DATA JPA
Using Spring Data JPA can save you a lot of time when
interacting with the database.
Spring Data JPA implements the Repository Pattern.
Domain Driven Design
Create a Persistence Repository
Defining a repository for our City domain class is as simple as
defining a interface and extending the CrudRepository
interface.
SPRING BOOT WEBAPPLICATION
Thymeleaf is a modern server-side Java template engine for
both web and standalone environments.
Thymeleaf is ideal for modern-day HTML5 JVM web
development
http://www.thymeleaf.org/
Gradle Dependency for Thymeleaf
Create a HelloController
dependencies {
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
}
37.
SPRING BOOT WEBAPPLICATION
Create a greeting.html
src/main/resources/templates/greeting.html
Run and Testing
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>
38.
SPRING BOOT WEBAPPLICATION
Spring Boot Admin – HTTP API Monitoring
39.
SPRING BOOT APPLICATION
Project Package Layout
Spring Boot main application class
Resources Layout