[JAVA] Start web application development with Spring Boot

Overview

--Try to make a simple web application with Spring Boot ――In this article, first of all, something like Hello World -** Even people with no development experience can easily get started **

What is Spring Boot in the first place?

--One of the frameworks in Java development --The feature is that it requires less initial settings and is easy to start using.

Development environment

environment service/version
OS Mac
language Java8
IDE(Integrated development environment) IntelliJ IDEA
Framework SpringBoot 2.2.1

--Java must be installed in the development environment

Creating a template

Use Spring Initializr

--Web service that allows you to create a template application for Spring Boot --You can select the build tool (Maven / Gradle) and language (Java / Kotlin / Groovy).

procedure

Specify the following

--Build tool ――Both are commonly used, so either one is fine, but this time I will use Gradle. --Language --Spring Boot version

01-initializr.png

--Click the Generate button to download the template app as a zip

Check the template app

02-app.png

--Files such as SpringStudyApplication.java and ʻapplication.properties are created by default --SpringStudyApplicationTests.java` is unnecessary, so delete it

Try Hello World

――If you keep the template, it won't work, so first of all, Hello World --When accessing http: // localhost: 8080 / hello, Hello World! Is displayed.

procedure

--Create a class that accepts requests and returns strings

HelloRestController.java

--Create HelloRestController.java in com.examle.springstudy

com.examle.springstudy.HelloRestController.java


package com.example.springstudy;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController // ①
public class HelloRestController {
    @GetMapping("/hello") // ②
    public String hello() {
        return "Hello World!";
    }
}

--Two annotations are the point (@ XXX) -①: Indicates that the controller accepts requests and returns responses. -②: Associate the request URL with the logic

Operation check

--Select the starting class (SpringStudyApplication) and execute (⌃ + ⌥ + R)

02-exec.png

--When started, the following contents are output to the console.

11:46:44: Executing task 'bootRun'...

> Task :compileJava
> Task :processResources
> Task :classes

> Task :bootRun

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.1.RELEASE)

2019-12-01 11:46:59.590  INFO 43520 --- [           main] c.e.springstudy.SpringStudyApplication   : Starting SpringStudyApplication on MacBookPro with PID 43520 (/Users/tanibuchi/Desktop/spring-study/spring-study/build/classes/java/main started by tanibuchi.kosuke in /Users/tanibuchi/Desktop/spring-study/spring-study)
2019-12-01 11:46:59.595  INFO 43520 --- [           main] c.e.springstudy.SpringStudyApplication   : No active profile set, falling back to default profiles: default
2019-12-01 11:47:00.598  INFO 43520 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-12-01 11:47:00.612  INFO 43520 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-12-01 11:47:00.612  INFO 43520 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-12-01 11:47:00.680  INFO 43520 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-12-01 11:47:00.680  INFO 43520 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1037 ms
2019-12-01 11:47:00.915  INFO 43520 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-12-01 11:47:01.089  INFO 43520 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-12-01 11:47:01.098  INFO 43520 --- [           main] c.e.springstudy.SpringStudyApplication   : Started SpringStudyApplication in 2.169 seconds (JVM running for 3.005)

--If Started is displayed at the end, it can be started normally. --When you access http: // localhost: 8080 / hello, the following screen will be displayed.

03-helloworld.png

Finally

――You can easily start application development using Spring Boot like this. ――This time, it is described at the summary level, so I will explain it a little more carefully next time.

Recommended Posts

Start web application development with Spring Boot
Run WEB application with Spring Boot + Thymeleaf
[Spring Boot] Web application creation
Spring Boot2 Web application development with Visual Studio Code SQL Server connection
Spring Boot2 Web application development with Visual Studio Code Hello World creation
Until you start development with Spring Boot in eclipse 1
Until you start development with Spring Boot in eclipse 2
Spring Boot application development in Eclipse
Hot deploy with Spring Boot development
Inquiry application creation with Spring Boot
Processing at application startup with Spring Boot
Launch Nginx + Spring Boot application with docker-compose
Let's make a book management web application with Spring Boot part1
Let's make a book management web application with Spring Boot part3
Let's make a book management web application with Spring Boot part2
Spring Boot 2.3 Application Availability
Download with Spring Boot
Configure Spring Boot application with maven multi module
Create a web api server with spring boot
Create a Spring Boot development environment with docker
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 1/3 [Preparation]
Spring5 MVC web application development with Visual Studio Code SQL Server connection
Spring5 MVC Web application development with Visual Studio Code Maven template creation
Introduction to Java development environment & Spring Boot application created with VS Code
Generate barcode with Spring Boot
Hello World with Spring Boot
Implement GraphQL with Spring Boot
Try using OpenID Connect with Keycloak (Spring Boot application)
Hello World with Spring Boot!
Run LIFF with Spring Boot
SNS login with Spring Boot
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 2/3 [Page creation 1/2]
File upload with Spring Boot
Web application development article summary
Spring Boot starting with copy
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 3/3 [Page creation 2/2]
CICS-Run Java application-(4) Spring Boot application
Spring Boot starting with Docker
Hello World with Spring Boot
Set cookies with Spring Boot
Use Spring JDBC with Spring Boot
Web application built with docker (1)
Add module with Spring Boot
Getting Started with Spring Boot
I tried to clone a web application full of bugs with Spring Boot
Roughly the flow of web application development with Rails.
Create microservices with Spring Boot
Send email with spring boot
A story that stumbled when deploying a web application created with Spring Boot to EC2
Implement REST API with Spring Boot and JPA (Application Layer)
The first WEB application with Spring Boot-Making a Pomodoro timer-
Sample web application that handles multiple databases in Spring Boot 1.5
Java web application development environment construction with VS Code (struts2)
Spring Boot application that specifies DB connection settings with parameters
Introducing Spring Boot2, a Java framework for web development (for beginners)
Domain Driven Development with Java and Spring Boot ~ Layers and Modules ~
[Java] Sample project for developing web applications with Spring Boot
Use Basic Authentication with Spring Boot
gRPC on Spring Boot with grpc-spring-boot-starter
Create an app with Spring Boot 2
Database linkage with doma2 (Spring boot)