http://start.spring.io
Spring Boot 2.X - Requisito mínimo java 8
Spring Boot 1.X - Suporta java 6,7,8 e não tem planos para suporte java 9
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.ractecnologia.templates</groupId>
<artifactId>spring-boot2</artifactId>
<version>0.0.1-RC1</version>
<packaging>jar</packaging>
<name>spring-boot2</name>
<description>Project Spring Boot Template</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
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);
}
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class CommandLineRunnerImpl implements CommandLineRunner {
private static Logger log = LoggerFactory
.getLogger(CommandLineRunnerImpl.class);
@Override
public void run(String... args) throws Exception {
log.info("EXECUTING : command line runner");
}
}
maven
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
uso
@Getter
@Setter
@Slf4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
LiveReload - plugin do Chrome para atualizar página
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Necessita de um projeto web. Gera diversos endpoints para testar nosso app.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Na linha de comando (Spring Boot CMD):
java -jar nome_projeto.jar
mvn spring-boot:run
mvn spring-boot:run -Dspring-boot.run.profiles=dev
mvn spring-boot:run -Dspring-boot.run.arguments="--spring.profiles.active=local --app.datasource.conecta.jdbcUrl=jdbc:oracle:thin:@10.206.53.100:1521:banco --spring.jackson.time-zone=UTC" -Drun.jvmArguments="-Duser.timezone=UTC"
Para CreateProcess error=206
mvn spring-boot:run -Dspring-boot.run.profiles=dev -Dspring-boot.run.fork=false
Mudando a porta:
java -Dserver.port=8080 -jar nome_projeto.jar
application.properties
logging.level.org.springframework = debug
logging.level.br.com.ractecnologia = info
Habilitando logging.level.org.springframework = debug
para debug, podemos ver todas as configurações quando iniciamos o servidor.
application.properties application-dev.properties application-hml.properties application-prd.properties
Na linha de comando
-Dspring.profiles.active=dev
Spring Boot 2
spring 5.0.4.RELEASE
slf4 1.7.25
tomcat 8.5
hibernate 5.2