Primi passi con Spring Boot

Marco Ballante - 04/02/2019

Come creare una semplice applicazione web per avvicinarsi a Spring Boot.

Ingredienti: maven, java 1.8, eclipse.

Per avviare lanciare il comando:

mvn package && java -jar target/simple_service-0.0.1-SNAPSHOT.jar

pom.xml

<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>it.gsoftware.service</groupId>
  <artifactId>simple_service</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  
  	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.2.RELEASE</version>
	</parent>
  
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>  
	<build>
		<plugins>
			<!-- Package as an executable jar/war -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>  
</project>

 

Controller

@RestController
public class WelcomeController {

    @RequestMapping("/")
    public String index() {
        return "Welcome to www.javajob.it!";
    }
}

 

@SpringBootApplication
@ComponentScan(basePackages = "it.gsoftware.simple_service.controllers")
public class Application {

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

 

Javajob.it © 2019 - Javajob.it è un progetto realizzato da Gsoftware srls