0% found this document useful (0 votes)
6 views63 pages

Spring Boot Project Initialization Guide

This document describes the principles and features of Spring Boot. It presents how to initialize a Spring Boot project, the generated structure, and the benefits provided such as simplifying configuration and integrating Spring frameworks.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views63 pages

Spring Boot Project Initialization Guide

This document describes the principles and features of Spring Boot. It presents how to initialize a Spring Boot project, the generated structure, and the benefits provided such as simplifying configuration and integrating Spring frameworks.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Orange September 2020

From Spring to Spring Boot


the Spring Boot conductor
the Spring Boot conductor
summary
Spring and its ecosystem
initialization of a Spring Boot project
-generated Spring Boot project
tests
- static pages
[Link]/.ymlet profiles
log management
monitoring
-deployment with Spring Boot

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
Spring and its ecosystem

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
Spring and its ecosystem
advantages
Spring brings a whole ecosystem of tools to facilitate application development. It supports (at least in part) certain
the most commonly encountered issues by developers:

Dependency injection with Spring Framework


access to data via Spring Data
the exhibition of REST API with Spring Web MVC
-security with Spring Security
-the writing of batches with Spring Batch
–...

Of course, these frameworks are interoperable with each other.

The goal is to let Spring handle as much as possible the technical mechanisms of development that are costly to implement.
place (plumbing). Thus, the developer focuses on the business rules of their application.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
Spring and its ecosystem
disadvantages
A project that is based on the Spring ecosystem requires:

know the functioning of the different Spring frameworks


know how to configure them (XML or annotations) individually
–know how to integrate them with each other (which versions are compatible...).

These configurations can prove to be:

voluminous (especially in XML)


scattered
redundant from projects to projects (dependency management for example).

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
Spring and its ecosystem
the solution
Spring Bootis a hat tool. Its purpose is to simplify:

– the configuration: conventions and default settings (Maven dependencies, Spring configuration), which ensure a good
integration of different frameworks
- execution: an application server (Tomcat, JettyorUndertow) is embedded in the application executable lejar/war
the implementation of microservices: support for libraries and a microservices platform
– deployment in a Cloud: help with configuration, tools, Cloud clients. Integration with Cloud Foundry

Spring Boot addresses both:

to developers familiar with the Spring ecosystem


to beginners in Spring, who will apprehend it more quickly and simply.

Spring Boot takes the logic of simplification and integration initiated by Spring to its maximum.

Note: Spring Boot does not provide new solutions to issues already addressed by other frameworks.
Spring.

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
Spring and its ecosystem
Spring Boot
Spring Boot relies on 3 main components:

–desSpring Boot Starter: reduction of dependencies in the build file


gathers a related group of dependencies (common domain) into a single dependency
There are many starters (web, data-jpa, security, test...)
-[Link] very compact and easy to read/modify
Spring AutoConfigurator: reduction of Spring configuration
framework autoconfiguration without XML file
reduction of Java annotations to explicitly mention
possibility to override this configuration in a .properties/yml file
Spring Actuator: Spring Boot application monitoring tools
-tracking metrics (logs, list of beans, thread dump...)
creating its own metrics
addition of REST endpoints

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
initialization of a Spring Boot project

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
initialization of a Spring Boot project
Several methods (of your choice) are available to generate a Spring Boot project skeleton. They all rely on Spring Initializr, via:

aweb interface
the IDESpringToolsorIntelliJ
– Spring Boot CLI (Command Line Interface)
– cURL

Based on the choices expressed by the user (Web, JPA, Security, Cloud...), the project skeleton is created, particularly by adding the
necessary Maven dependencies (the starters).

Note:

The generated project is not a multi-module Maven project, as it is more microservices oriented.
There is no business code, so the project cannot be tested directly, unlike the old Orange Maven.
Archetypes

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
initialization of a Spring Boot project
Spring Initializr via une interface web
Spring Initializr is a web page that allows you to generate a Spring Boot project in the form of a .zip file. This file can be imported into a
IDE once unzipped.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
initialization of a Spring Boot project
Spring Initializr via Spring Tools or IntelliJ
SpringTools relies on the IDEEclipse, customized to simplify Spring application development.

It includes a set of plugins in addition to the core Eclipse framework:

–analysis of Spring bean dependencies


Spring project validation
–support des annotations ou de la configuration XML Spring
graphic editors for Spring Batch, Spring Integration
supervision of Spring beans during application execution
integration with Pivotal tools: Cloud Foundry and tc Server (Tomcat optimized for Spring)
Git
Maven
–...

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
initialization of a Spring Boot project
Spring Initializr via Spring Tools or IntelliJ
Whether in SpringTools or IntelliJ, a wizard integrates Spring Initializr: File/New/Spring Starter Project

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
initialization of a Spring Boot project
Spring Initializr via Spring Tools or IntelliJ
Next, you need to fill in the information (Maven among others) requested:

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
initialization of a Spring Boot project
Spring Initializr via Spring Tools or IntelliJ
Enfin, il faut sélectionner les briques Spring dont on a besoin :

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
initialization of a Spring Boot project
Spring Initializr via Spring Boot CLI
Spring Boot CLI is a tool that allows you to run tasks from the command line (no need to open an IDE), for example:

– spring help <commandName>: get the details of the desired order


spring init: initialize a project from Spring Boot templates (Spring Initializr)
spring test: compile and run the application tests
spring jar: generate an executable jar from the project's sources
– spring run: execute a Groovy script
–...

Example of creating a new Maven project:

–in a directory MyProject


using spring-boot-starter-web and spring-boot-starter-data-jpa
–the main class is called MyProjectApplication

spring init --name=MyProjectApplication --dependencies=web,data-jpa MyProject

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
initialization of a Spring Boot project
Spring Initializr via cURL
cURL is an open-source library and a command-line tool for transferring data using various protocols (HTTP,
HTTPS, FTP, SMTP, LDAP...

The commands are in the form: curl [URL] [options] or curl [options] [URL]

It can be used to access the creation of a Spring Initializr project, for example:

curl [Link]
-d applicationName=MyProjectApplication
-d dependencies=web,data-jpa
-o [Link]

For more information on parameters and possible dependencies:

curl [Link] -H 'Accept: application/json'

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
generated Spring Boot project

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
generated Spring Boot project
structure of a Spring Boot project
The project generated by Spring Initializr is a Maven (or Gradle) project containing at least:

–src/main/java: the main class of the application


–in src/main/resources:
/static for static files (html, images...)
- /templates for the templates of templating engines
(FreeMarker, Groovy, Thymeleaf, and Mustache)
- [Link] for configuration (e.g.: url of the
base de données, messages internationalisés...)
–src/test/java: the skeleton of a test class of
the application
a .gitignore file to exclude certain files from version control
in Git
- a [Link] file listing useful links
- a script [Link] to install Maven and run goals
in command line
–[Link] with the selected dependencies.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
Spring Boot project generated
Maven configuration without corporate pom
[Link] of the application inherits from a parent (spring-boot-starter-parent) provided by Spring Boot:

<parent>
<groupId>[Link]</groupId>
spring-boot-starter-parent
<version>[Link]</version>
<relativePath/><!-- lookup parent from repository -->
</parent>

This parent brings:

a set of Spring dependencies as <dependencyManagement>


a homogeneity in the versions of embedded Spring (and other) dependencies
the consideration of UTF8
a standard configuration of the plugins
–...

Reminder: the <dependencyManagement> section in [Link] declares dependencies but does not import them. It needs to specify.
those that we really want to use in the <dependencies> section.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
generated Spring Boot project
Maven configuration with corporate pom
If we are to inherit from a corporate parent, it is no longer possible to inherit from the spring-boot-starter-parent (only one parent is possible).

We bypass the problem by adding spring-boot-dependencies as a <dependencyManagement>, with an <scope>import</scope>


and<type>apple</type>:

<dependencyManagement>
<dependencies>
<dependency>
Import dependency management from Spring Boot
[Link]
spring-boot-dependencies
<version>[Link]</version>
pom
import
</dependency>
</dependencies>
</dependencyManagement>

Note: concrètement, lespring-boot-starter-parenthérite lui-même despring-boot-dependencies.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
generated Spring Boot project
Maven configuration: the dependencies
Then we find starters offered by Spring as dependencies, based on the choices made in Spring Initializr:

spring-boot-starter-web: support for web development (Spring MVC, Tomcat...)


- spring-boot-starter-data-jpa: support for JPA (Spring Data, Spring ORM, Hibernate...)
spring-boot-starter-test: support for common test dependencies (JUnit, Mockito, Hamcrest...)
spring-boot-starter-security: support for Spring Security
–...

Note: it is not necessary to specify the dustarter version, it is configured in the spring-boot dependency.
dependencies.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
generated Spring Boot project
Maven configuration: property overriding
By default, many properties, including library versions, are set by Spring Boot.

It is possible to change them in the <properties> section of [Link] of the application, by overriding those declared in the [Link].
spring-boot-dependencies:

<properties>
...
<[Link]>11</[Link]>
<[Link]>1.7.29</[Link]>
...
</properties>

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
generated Spring Boot project
Maven configuration: executable jar/war
By default, an executable jar (fat jar) is generated, but it is also possible to have an executable war (fat war):

by specifying the desired packaging in the [Link] (typically in Maven)


-thanks to the pluginspring-boot-maven-plugin

<packaging>jar</packaging>or war

...

<build>
<plugins>
<plugin>
[Link]
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Note: we will see later in the training which packaging to prioritize.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
generated Spring Boot project
Java code
The main class of the application (annotated with @SpringBootApplication) has been generated in the base package.

This annotation will among other things scan the current package and sub-packages to detect Spring beans (annotated @Named,
Component, Controller, Service...

This main class contains the main() method which is used to run the application.

The business code remains the responsibility of the developer.

[Link];

import [Link];
import [Link];

@SpringBootApplication
public class ToDoListDemoApplication {

public static voidmain(String[] args) {


[Link]([Link], args);
}
}

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
tests

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
tests
Maven configuration
With Spring Initializr, thespring-boot-starter-testis automatically added in [Link]:

dependency
<groupId>[Link]</groupId>
spring-boot-starter-test
test
<exclusions>
<exclusion>
<groupId>[Link]</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

This starter brings dependencies to (among others):

JUnit: the standard for unit testing in Java


Spring Test: Spring Boot Test: support for testing Spring and Spring Boot applications
Hamcrest: library for object comparisons (equalTo(), hasItems(), containsString()...)
Mockito: framework for creating mocks

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
tests
unit tests
We can create unit test classes using JUnit:

@SpringBootTest(webEnvironment=[Link].RANDOM_PORT,
properties="classpath:[Link]")
public class ToDoList_API_Test {

...

@LocalServerPort
private int port;

BeforeEach
public void setUp() throws Exception {...}

@Test
public voidfindAllToDoLists_OK()throwsException {...}

...
}

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
static pages

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
static pages
To add static files (HTML pages...) to a Spring Boot application, you need to place them in the directory
src/main/resources/static(ousrc/main/resources/public).

We can override the default error page of Spring Boot with customized pages. They must:

to be located in src/main/resources/static/error (or /public/error)


to be named:
-be<HTTPStatusCode>.html (example: [Link])
-either<classStatusHTTP>.html(example: [Link])

For more information on page error overload, visitthe Spring Boot documentation.

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
properties/.yml files and profiles

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
properties/.yml files and profiles
The configuration of an application and the embedded frameworks by Spring Boot can be done using .properties and/or .yml files.

The [Link] looks a lot like .json. It's useful for defining hierarchical configuration data (but be careful of
respect for indentation !).

The main configuration file [Link] (or [Link]) can, for example, define:

the management of logs (LogBack by default, implementing the SLF4J standard)


the access information to a database (URL, user, password...)
functional messages (labels, errors...)
–...

Here is aliste non exhaustive available properties.

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
properties/.yml files and profiles
This configuration file can be divided into several files according to the nature of the information contained, and to prevent it from being too
bulky.

Moreover, we can define multiple profiles:

to provide different configurations depending on the target environments (development, testing, integration, production...)
–which will overload those defined in the default file.

These .properties/.yml files can be externalized outside of the jar/war.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
properties/.yml files and profiles
To create profiles, you need to create a file application-<profileName>.properties/.yml for each profile:

- [Link] or [Link]
[Link] or [Link]

#[Link]
[Link]

#[Link]
[Link]

#[Link]
server
port:4431

#[Link]
server
port:4432

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
properties/.yml files and profiles
In yaml format, we can also declare everything in the main [Link] file, separating the profiles with ---:

spring
application:
name: demoservice
server:
port:8080

---
spring:
profiles: dev
server
port:4431

---
spring:
profiles: prod
server
port:4432

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
properties/.yml files and profiles
profile selection
To run an application with a specific profile, we have 2 solutions:

– by passing parameters when launching the application:

java -jar <projectJarName>.jar -[Link]=<profileName>

–by specifying it in the main configuration file:

#[Link]
[Link]=prod

When a profile is launched, the corresponding file is read after the main configuration file [Link]/.yml, which allows
to overload one's properties.

Note: If you deploy an application in Cloud Foundry, the [Link]/.yml file will be loaded by
default. It is therefore not necessary to specify the active profile.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
properties/.yml files and profiles
best practices
Voici l'ordre de priorité des [Link]/.yml:

Profile file placed outside of the jar/war


profile file placed in lejar/war
main configuration file placed outside the jar/war
Main configuration file placed in lejar/war

Advice:

collect the common (or default) properties for all environments in one or more files
.properties/.yml, to be deployed in the jar/war (messages...)
externalize the environment-dependent configuration into one or more profile files deployed in
outside of war.

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
log management

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
log management
configuration in the .properties/.yml file
Spring Boot has a default configuration for Logback (rolling policy, pattern...) that can be modified (partially) directly in
the file [Link]/yml.

#properties
[Link]= WARN
[Link]= DEBUG
[Link]= /tmp/[Link]

#yml
logging:
level:
root: WARN
[Link]: DEBUG
file: /tmp/[Link]

Completion helps with writing keys.

More details on thelog managementin Spring Boot as well asprofiles.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
log management
configuration in the .xml file
It is of course also possible to modify the default configuration of Logback by using its own .xml file:

- [Link] (loaded by default)


- logback<Xxx>.xml (to be specified with the key [Link]).

[Link]= /tmp
[Link]= classpath:[Link]

<?xml version="1.0"encoding="UTF-8"?>
<configuration>

<!-- ${LOG_PATH} = [Link] du properties/yml -->


<propertyname="LOG_FILE"value="${LOG_PATH}/[Link]"/>

<includeresource=org/springframework/boot/logging/logback/[Link]

<loggername=[Link] level="DEBUG"/>
<loggername=[Link] level="INFO"/>
<loggername=[Link] level="INFO"/>

</configuration>

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
log management
externalization and centralization of logs
In the case of an application or microservices deployed on PaaS, it is necessary to be able to externalize the logs, in order to:

collect the logs written to standard output


store them in a dedicated space
to visualize them using an appropriate web application.

This allows to:

consolidate the logs of different microservices of the same application


to track the session, to see the sequence of calls of the microservices for the same use case.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
log management
externalisation et centralisation des logs
This centralized log management system is directly available in the Cloud Foundry and Kermit PaaS.

It is based on the open-source ELK stack:

– Elasticsearch:
NoSQL database
massive data storage, especially logs
search engine, indexing and data analysis
– Logstash:
pipeline accepting input data from different sources
makes transformations, aggregations... on this data
export the data to other tools, including Elasticsearch for storage
– Kibana:
web interface allowing exploration of data stored in Elasticsearch
very varied graphic renditions (scatter plots, curves, graphs...)

Cloud Foundry uses a serviceLogsearchopen source above ELK, allowing to manage an ELK environment in a context
cloud.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
log management
externalization and centralization of logs
In addition to these platforms on the application side:

– Spring Cloud Sleuth:


implement a transparent distributed log management solution
capture the logs on standard output
- enriches them, notably by adding attributes (and HTTP headers):
- traceId: identifiant des traces liées à une même requête utilisateur (use-case)
- spanId: identifiant des différents composants/microservices appelés, en gardant le mêmetraceId
-these identifiers will allow for a precise search (in ELK) of the path of a request through the
microservices
send them if necessary to an external storage service (for example ELK)
– Logstash-Logback-encoder:
Logback extension for transforming logs into JSON format (among others)
allows configuring the structure of the logs.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
log management
outsourcing and centralization of logs
The integration with Spring Boot is simple and transparent at the code level.

In the [Link] file, the following dependencies must be included:

<properties>
<[Link]>6.4</[Link]>
</properties>

<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>

<dependency>
[Link]
logstash-logback-encoder
<version>${[Link]}</version>
</dependency>
</dependencies>

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
log management
externalization and centralization of logs
It is also necessary to add the following dependencyManagement (the same as for OpenFeign):

<dependencyManagement>
<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${[Link]}</version>
pom
import
</dependency>
</dependencies>
</dependencyManagement>

By default, Sleuth only sends 10% of the logs to the remote platform. It is possible to change this percentage in the file.
[Link]:

between0and1
[Link] =0.5

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
log management
externalization and centralization of logs
Finally, you need to use the class LogstashEncoder to transform the logs into JSON, using the configuration file [Link]:

<?xml version="1.0" encoding="UTF-8"?>


<configuration>
<!-- import Spring Boot defaults -->
<includeresource=org/springframework/boot/logging/logback/[Link]"/>

<appendername=JSON
<encoderclass=[Link]>
</appender>

<rootlevel=INFO
<appender-ref ref=JSON
</root>
</configuration>

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
monitoring

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
monitoring
initialization with Spring Initializr
With Spring Initializr, you need to select the Actuator option in the Ops section.

The other options are available for previous versions of Spring Boot. Notably Actuator Docs which added the
Actuator documentation directly in the application in the form of a predefined endpoint (URL).

The project generation will add the Maven dependency accordingly.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
monitoring
Maven configuration
Whether it's with Spring Initializr or manually, you need to have the dependency for spring-boot-starter-actuator:

<dependency>
<groupId>[Link]</groupId>
spring-boot-starter-actuator
</dependency>

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
monitoring
features provided
Actuator addendpoints (URLs)to your application, in order to interact with it and supervise it:

/beans: displays the complete list of Spring beans in the application


/health: displays the status of the application (operational or not, + other information if you are authenticated: disk space,
database...)
- /info: displays information at your convenience (empty by default)
/loggers: displays and modifies the log configuration
/metrics: displays the used/available memory, number of active sessions, number of loaded classes...
- /mappings: displays all accessible URLs (thanks to the @RequestMapping annotations)
/shutdown: graceful shutdown of the application
/threaddump: performs a thread dump (list of all running threads)
–...

By default, all these endpoints are allowed (except/shutdown) but not necessarily exposed (thus not accessible). We can change their
individual authorization in the [Link]/yml file:

[Link]=true
[Link]=false

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
monitoring
features provided
These endpoints can be exposed (whether authorized or not) via JMX and/or HTTP. It is possible to modify their exposure on one
or the other technology:

only expose health and info via JMX


[Link]=health,info
expose everything except threaddump via HTTP
[Link]=*
[Link]=threaddump

By default, on HTTP:

-a prefix (/actuator) is added to the endpoint (e.g:[Link]


–only/health/information is exposed (and therefore authorized and accessible).

Attention: do not expose and allow certain endpoints without securing them, as they may provide sensitive information.
on the application. If Spring Security is present, they are secured by default (except /health/info) and require a
authentication. It is possible to modify the access rights of each endpoint based on roles.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
monitoring
features provided
It is possible to modify certain default parameters (ports, endpoint URLs...) in the [Link]/yml file:

change the port for the application (default: 8080)


[Link]=9000
authorize SSL for the application
[Link]=true
Change the port for the monitoring endpoints
[Link]=9001
authorize SSL for monitoring endpoints
[Link]=true
# change the default prefix (/actuator): /manage/health, ...
[Link]-path=/manage

Finally, it is possible to create your own endpoints (exposed via JMX or HTTP or both).

from Spring to Spring Boot - the Spring Boot conductor (Orange internal)
monitoring
added features
To display information for the endpoint/info, simply add your own keys (free) by prefixing them with info. in the file
[Link]/yml:

# informations pour '/info' : info.<nomLibre>: <valeurLibre>


[Link]:ToDoList Demo
[Link]:Mickael Cormier

Other information about the application, taken from the file [Link] (name, groupId, artifactId, build date...), can be added directly.
thanks to the configuration of the pluginspring-boot-maven-plugin:

<plugin>
<groupId>[Link]</groupId>
spring-boot-maven-plugin
<executions>
<execution>
<goals>
Generates build information (used by actuator info)
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
deployment with Spring Boot

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
deployment with Spring Boot
fat jar or fat war?
As we have already mentioned, Spring Boot offers the possibility to create a fat jar or a fat war, including an embedded Tomcat.

In production, in case of use:

-a PaaS: the use of the jar file is recommended, as we are sure that the Tomcat/jar pair is identical from one end of the chain to the other.
production. Supervision is the responsibility of the PaaS.
- of a Plato platform: it is better to rely on a fat deployed in a Plato-ized Tomcat.

Note that an unfat war can be both self-executable and deployed in a classic Tomcat. The embedded Tomcat is then ignored.

So, it is appropriate to distinguish 2 phases:

–development: on the developer's position, the use of embedded Tomcat is very practical
–from continuous integration: deploy this same fat war but in an external Tomcat as close as possible to the production one.
This is to avoid platform differences between testing and production.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
deployment with Spring Boot
deploy the jar locally via command line
First, you need to build the application with Maven to obtain the executable jar (with an embedded Tomcat).

Then, you need to execute the command:

java -jar <projectJarName>.jar

To activate a specific profile:

java -jar <projectJarName>.jar -[Link]=<nomProfil>

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
deployment with Spring Boot
deploy the jar locally via command line
After a few seconds, the application is deployed and available at the address: [Link]

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
deployment with Spring Boot
deploy the jar locally from an IDE
In SpringTools: right-click on the project Run As Spring Boot App

In IntelliJ: right click on the project Run SpringBootWebApplication

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
deployment with Spring Boot
deploy the jar locally from an IDE
In SpringTools (and IntelliJ?), there is a viewSpring Boot Dashboard.

It allows to:

start/stop a Spring Boot application


Know the status of the applications declared in the dashboard (URL, port...)
to integrate with Cloud Foundry...

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
deployment with Spring Boot
deploy the war on an external server
To generate and deploy a WAR in an external container (e.g., Tomcat), it is preferable to create a specific Maven profile in the
[Link]. By default, the jar is produced, and the war only when the profile is activated:

<profiles>
<profile>
<id>deploy-war</id>
<properties>
war
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>[Link]</groupId>
spring-boot-starter-tomcat
provided
</dependency>
</dependencies>
</dependencyManagement>
...
</profile>
</profiles>

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
deployment with Spring Boot
deploy the war on an external server
In addition, the main class of the application must extend the SpringBootServletInitializer class and override the method
configure():

@SpringBootApplication
public class ToDoListDemoApplication extends SpringBootServletInitializer {

public static void main(String[] args) {


[Link]([Link], args);
}

@Override
protectedSpringApplicationBuilderconfigure(SpringApplicationBuilder builder) {
[Link]([Link]);
}
}

This replaces the traditional configuration file [Link], and possibly adds configuration (default profile,
launch arguments of the application...

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
deployment with Spring Boot
deploy the war on an external server
TheMaven Cargo pluginallows you to simplify the deployment of the war on the platform of your choice (locally or remotely):

<plugin>
[Link]
cargo-maven2-plugin
<version>${[Link]}</version>
Server information: url, port, user, pwd...
...
</plugin>

This plugin would be useful in the deploy-war profile presented earlier for example.

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
documentation
Official siteSpring Boot
Spring BootReference Guide
Documentation on theMaven configuration of Spring Boot
Documentation onSpring Actuator
SiteSpring Initializr
-SiteSpringTools
Articles onSpring Boot Dashboard
GitHubSpring Initializr CLI
SiteElastic
–SiteLogsearch
SiteSpring Cloud Sleuth
-SiteSpring Framework GURUmany tutorials
–SiteBaeldungmany tutorials
–TutorialSpringa lot of information on the installation and use of tools related to Spring (Spring Core, Spring MVC, Spring
Security, SpringTools, Spring Boot, Spring Boot CLI, cURL...)

Guide ofmigration de SpringBoot 1.5 à SpringBoot 2.0

From Spring to Spring Boot - the Spring Boot conductor (Orange internal)
thank you

You might also like