Spring-Boot revealed – What is Spring-Boot? – Getting started



Spring-Boot revealed – What is Spring-Boot? – Getting started

0 0


reveal-spring-boot

Spring-Boot presentation

On Github Juwit / reveal-spring-boot

Spring-Boot revealed

Julien WITTOUCK

About Me

Software Architect at Sopra Steria (XNet)

Au menu

  • What is Spring-Boot?
  • Getting started
  • Getting further

About Java

What is Spring-Boot?

Dependency Injection

Dependency Injection

Spring's way : IoC Container (Inversion of Control)

Configuration Metadata

XML based configuration

<bean id="exampleBean" class="examples.ExampleBean">
    <!-- setter injection using the neater ref attribute -->
    <property name="beanTwo" ref="yetAnotherBean"/>
    <property name="integerProperty" value="1"/>
</bean>

<bean id="anotherExampleBean" class="examples.AnotherBean"/>
<bean id="yetAnotherBean" class="examples.YetAnotherBean"/>

Configuration Metadata

Java annotations

@Component
public class SimpleMovieLister {

    private MovieFinder movieFinder;

    @Autowired
    public void setMovieFinder(MovieFinder movieFinder) {
        this.movieFinder = movieFinder;
    }
}

Spring IO EcoSystem

Spring-Boot

  • Getting started very quickly with Spring
  • Non-functional requirements
  • Production ready

Getting started

start.spring.io

Live Demo

Getting further

... Now that you know the force

Packaging for production

Maven plugin (using spring-boot-starter-parent):

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
$ mvn package

Gradle plugin:

apply plugin: 'spring-boot'
$ gradle repackage

Packaging for production

$ java -jar yourapp.jar
  • No start script required
  • Typical REST service ~10Mb
  • Cloud Friendly (works & fast to upload)

Command Line Arguments

SpringApplication adds command line arguments to the Spring Environment so you can refer inject them into beans:

@Value("${name}")
private String name;
$ java -jar target/yourapp.jar --name=Dave

You can also configure Spring Boot itself:

$ java -jar target/*.jar --server.port=9000

Externalizing Configuration

to Properties

Just put application.properties in your classpath or next to you jar, e.g.

server.port: 9000

Using YAML

Just include snake-yaml.jar and put application.yml in your classpath

server:
    port: 9000

Spring Profiles

Activate external configuration with a Spring profile file name convention e.g. application-development.properties

Set the default spring profile in external configuration, e.g:

spring.profiles.active: default, postgresql

Actuator

Adds common non-functional features to your application and exposes MVC endpoints to interact with them.

  • Security
  • Secure endpoints: /metrics, /health, /trace, /dump, /shutdown, /beans, /env
  • /info
  • Audit
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Actuator

http://localhost:8080/metrics
{
    "mem": 582443,
    "mem.free": 426152,
    "processors": 4,
    "instance.uptime": 43066,
    "uptime": 52326,
    ...
}

Integration with Docker

Integration with Docker

DockerFile

FROM java:8
ADD youapp.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]

build your image and run anywhere!

Integration with Docker

Demo

Thank you!

Questions?

Spring-Boot revealed Julien WITTOUCK