From creating a Spring Boot project to running an application with VS Code

Overview

I created a Spring Boot web application with VS Code, so I will describe the procedure

environment

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.14.3
BuildVersion:	18D109

$ java -version
openjdk version "12" 2019-03-19
OpenJDK Runtime Environment (build 12+33)
OpenJDK 64-Bit Server VM (build 12+33, mixed mode, sharing)

$ code -v
1.32.1

Extension installation

Install the following extensions as they are required when developing with VS Code

Java Extension Pack Spring Boot Extension Pack

Project creation

After installing the extension, search for spring in the command palette and Spring Initializr: Select Generate a Maven Project

image.png

Select Java

image.png

Enter the package name

image.png

Enter the project name

image.png

Select Spring Boot version

image.png

Add web and Thymeleaf to dependencies

Spring Web

スクリーンショット 2019-11-05 21.29.52.png

Thymeleaf

image.png

Choose a location to save your project

Application execution

DemoApplication.java is created in src / main / java / com / example / sampleproject, main method is implemented

DemoApplication.java


package com.example.sampleproject;

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

@SpringBootApplication
public class DemoApplication {

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

}

Create a controller folder in src / main / java / com / example / sampleproject and Create SampleController.java in it

SampleController.java


package com.example.sampleproject.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class SampleController {

    @RequestMapping("/sample")
    public String sample() {
        return "sample";
    }
}

Create sample.html in src / main / resources / templates

sample.html


<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Sample</title>
</head>

<body>
    <h1>HelloWorld</h1>
</body>

</html>

Debug → Select Start Debugging and select Java in the environment selection.

Since launch.json is generated, select Debug again → Start debugging

Because the Spring Boot application launches on the local server HTML content is displayed when connecting to the following URL

http://localhost:8080/sample

Recommended Posts

From creating a Spring Boot project to running an application with VS Code
What I was addicted to when developing a Spring Boot application with VS Code
Run a Spring Boot project in VS Code
Introduction to Java development environment & Spring Boot application created with VS Code
Spring Boot programming with VS Code
Try using Spring Boot with VS Code
Sample code to unit test a Spring Boot controller with MockMvc
How to open a script file from Ubuntu with VS code
Connect with VS Code from a Windows client to Docker on another server
03. I sent a request from Spring Boot to the zip code search API
I tried to clone a web application full of bugs with Spring Boot
How to create a Spring Boot project in IntelliJ
[Spring Boot] How to create a project (for beginners)
A memorandum when creating a REST service with Spring Boot
Load an external jar from a Spring Boot fat jar
From building an AWS cloud environment to deploying a Spring Boot app (for beginners)
Try Spring Boot from 0 to 100.
A story that stumbled when deploying a web application created with Spring Boot to EC2
A memo to start Java programming with VS Code (2020-04 version)
A new employee tried to create an authentication / authorization function from scratch with Spring Security
Spring Boot application code review points
Create an app with Spring Boot 2
[Rails] Creating a new project with rails new
About creating an application with springboot
Inquiry application creation with Spring Boot
Create an app with Spring Boot
Upgrade spring boot from 1.5 series to 2.0 series
Switch from Eclipse to VS Code
Let's make a book management web application with Spring Boot part1
02. I made an API to connect to MySQL (MyBatis) from Spring Boot
Let's make a book management web application with Spring Boot part3
Let's make a book management web application with Spring Boot part2
Processing at application startup with Spring Boot
Create a Spring Boot app development project with the cURL + tar command
Spring Boot2 Web application development with Visual Studio Code SQL Server connection
[Spring Boot] Precautions when developing a web application with Spring Boot and placing war on an independent Tomcat server
Java beginner tried to make a simple web application using Spring Boot
Spring Boot2 Web application development with Visual Studio Code Hello World creation
Story when moving from Spring Boot 1.5 to 2.1
Start web application development with Spring Boot
Changes when migrating from Spring Boot 1.5 to Spring Boot 2.0
Launch Nginx + Spring Boot application with docker-compose
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
# 1 [Beginner] Create a web application (website) with Eclipse from knowledge 0. "Let's build an environment for creating web applications"
Run WEB application with Spring Boot + Thymeleaf
When introducing JOOQ to Spring boot, a story that was dealt with because an error occurred around Liquibase
Points I stumbled upon when creating an Android application [Updated from time to time]
How to deploy a system created with Java (Wicket-Spring boot) to an on-campus server
Sign in to a Spring Boot web application on the Microsoft ID platform
[Spring Boot] How to get properties dynamically from a string contained in a URL
How to create an Excel form using a template file with Spring MVC
Create a website with Spring Boot + Gradle (jdk1.8.x)
Configure Spring Boot application with maven multi module
Create a simple search app with Spring Boot
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
Connect to Aurora (MySQL) from a Java application
How to use built-in h2db with spring boot
Create a Spring Boot application using IntelliJ IDEA
Try to implement login function with Spring Boot
How to add a classpath in Spring Boot
Build Spring Boot project by environment with Gradle