Spring Boot

Spring Platform Stack

Objectius

  •  >= Java 7
  • >= Spring Framework 4.1.5
  • Contenidors: Tomcat, Jetty, Undertow
  • Build tools: maven, gradle, Ant

Requeriments sistema

Mòduls

Spring Boot Core. Base pels altres mòduls

Spring Boot CLI. línia de comandes, start/stop d'aplicacions

Spring Boot Autoconfigure. Configuració de projectes spring

Spring Boot Actuator. Activa algunes característiques enterprise (Seguretat, Mètriques, pàginas d'error per defecte) a l'aplicació. És opcional.

Spring Boot Application Starters. Projectes Spring out of the box

Spring Boot Tools. Maven, Gradle & custom Spring Boot Loader

Spring Boot Samples. Exemples

  • spring-boot-starter-batch
  • spring-boot-starter-data-mongodb
  • spring-boot-starter-jdbc
  • spring-boot-starter-mobile
  • ...

 

  • spring-boot-starter-web
  • spring-boot-starter-test
  • spring-boot-starter-security
  • spring-boot-starter-redis
  • ...

Starters d'aplicació

+ Key Features 

 

SpringApplication class

Afegeix nous events i listeners

Web enviroment automàtic
CommandLineRunner interface

 Externalized Configuration 

RandomValuePropertySource

Accessing command line properties
 Placeholders in properties

 

Referència

 

<!-- Inherit defaults from Spring Boot -->
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.3.RELEASE</version>
</parent>

<dependencies>
    <!-- Add typical dependencies for a web application -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- Add typical dependencies for a batch application -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

pom.xml

bye bye  web.xml

package smc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

SpringApplication.run()

Configuració externa


 @Value("${api.referencia.municipis}")
 private String urlMunicipis;





 
 java -jar dades-amazon-0.1.0.jar --api.referencia.municipis="/aaaaa/v1/municipis"

 @Configuration
 @PropertySource("classpath:Global.properties")
 public class GeneralConfiguration {
   ....
 }

Habilitem properties

Recuperem valors

Valors random

 
 my.secret=${random.value}
 my.number=${random.int}
 my.bignumber=${random.long}
 my.number.less.than.ten=${random.int(10)}
 my.number.in.range=${random.int[1024,65536]}

Propietats en YAML

 
my:
   servers:
       - dev.bar.com
       - foo.bar.com


Equival a:

my.servers[0]=dev.bar.com
my.servers[1]=foo.bar.com

Gràcies!

Spring Boot

By Emilio Ponce

Spring Boot

  • 1,048