[Java] Sample project for developing web applications with Spring Boot

It is a template for advancing web application development using Java (Spring Boot). I made a sample project below. https://github.com/hrk-okd/spring-sample

Source code description

Creation environment

Thought of source creation

Since it is a sample, it is not a thought, but the only thing I wrote with one point in mind is that it uses the DI method with "constructor injection".

Sample project library structure

The library of the sample project is as follows.


Source
https://github.com/hrk-okd/spring-sample/blob/0710e4585767eb3dc260054b57d7607a9543bb60/spring-mvc/build.gradle#L18-L44

dependencies {
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot
    compile group: 'org.springframework.boot', name: 'spring-boot', version: '2.1.6.RELEASE'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter
    compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: '2.1.6.RELEASE'
    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.6.RELEASE'

    // https://mvnrepository.com/artifact/org.projectlombok/lombok
    compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.8'

    // junit 5
    // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.1'

    //mockito in general
    // https://mvnrepository.com/artifact/org.mockito/mockito-core
    testCompile group: 'org.mockito', name: 'mockito-core', version: '3.0.0'

    // mockito ExtendWith
    // https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter
    testCompile group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.0.0'

    // mockito assertThat().isEqualTo
    // https://mvnrepository.com/artifact/org.assertj/assertj-core
    testCompile group: 'org.assertj', name: 'assertj-core', version: '3.13.0'
}

spring-boot/spring-boot-starter/spring-boot-starter-web This is the basic library. If you use Spring Boot, don't think too much about it. If you don't create a web application, you can safely exclude spring-boot-starter-web. |

lombok Annotating classes and methods with @ Getter and @Setter eliminates the need to write getters and setters. This is really convenient.

Depending on the site, you may not want to install extra plugins. However, I personally think that it is essential to introduce it at all sites in order to improve development efficiency.

junit-jupiter This is a library for JUnit 5. JUnit4 has improved the difficulty of using it, so it is better to support it if possible.

mockito-core/mockito-junit-jupiter mockito is a library used for unit testing, and it is possible to use mock. There are several mock libraries, but I'm incorporating them because I thought it would be good to know in the field.

It is possible to use mock without mockito-junit-jupiter. However, if you use the @ExtendWith annotation that can be used in this library, you can create a mock by annotating the field. You can also reduce the effort of test code.

assertj-core This is also a library used for unit testing, and has a wealth of validation method asserts and related methods. It is possible to easily verify contents that are difficult to write with normal JUnit.

Summary

We have prepared a sample project for development with Spring Boot.

I think that more libraries will be needed for actual development, but it is better to prepare such a sample in order to configure from the minimum and gradually add functions. ..

With the rise of github in recent years, it is possible for individuals to have and publish many repositories. I think that the company will prepare a repository, but it is good to prepare a personal repository in advance so that you can quickly retrieve the necessary information.

Many customer-resident engineers cannot bring their own PCs, but it is rare that the source acquisition of github is restricted. To help you work comfortably, upload a source that summarizes the information.

Recommended Posts

[Java] Sample project for developing web applications with Spring Boot
Spring Boot: Restful API sample project
[Java] LINE integration with Spring Boot
Introducing Spring Boot2, a Java framework for web development (for beginners)
Create Java Spring Boot project in IntelliJ
Start web application development with Spring Boot
Run WEB application with Spring Boot + Thymeleaf
Personal memo Run Spring Boot + Gradle web project with Codenvy (Eclipse Che)
Run Scala applications with Spring Boot through Gradle
Build Spring Boot project by environment with Gradle
Java tips-Create a Spring Boot project in Gradle
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
[Rails] Building an environment for developing web applications
[Java] Article to add validation with Spring Boot 2.3.1.
Create a web api server with spring boot
Download with Spring Boot
Settings for connecting to MySQL with Spring Boot + Spring JDBC
[Java] [Spring Boot] Specify runtime profile --Spring Boot starting with NetBeans
[Spring Boot] How to create a project (for beginners)
[Java] Environment construction procedure for developing struts 1.3 with Eclipse
[Java / Kotlin] Escape (sanitize) HTML5 support with unbescape [Spring Boot]
Generate barcode with Spring Boot
Change the injection target for each environment with Spring Boot 2
Implement GraphQL with Spring Boot
Handle Java 8 date and time API with Thymeleaf with Spring Boot
Get started with Spring boot
Hello World with Spring Boot!
[Spring Boot] Web application creation
Run LIFF with Spring Boot
SNS login with Spring Boot
Preparation for developing with Rails
[Java] Thymeleaf Basic (Spring Boot)
File upload with Spring Boot
Spring Boot starting with copy
Sample web application that handles multiple databases in Spring Boot 1.5
CICS-Run Java application-(4) Spring Boot application
Using Mapper with Java (Spring)
Spring Boot starting with Docker
Try developing a containerized Java web application with Eclipse + Codewind
Set cookies with Spring Boot
Use Spring JDBC with Spring Boot
Add module with Spring Boot
Getting Started with Spring Boot
Domain Driven Development with Java and Spring Boot ~ Layers and Modules ~
Send email with spring boot
Spring Boot for annotation learning
Implement a simple Web REST API server with Spring Boot + MySQL
Let's make a book management web application with Spring Boot part1
How to make a hinadan for a Spring Boot project using SPRING INITIALIZR
Let's make a book management web application with Spring Boot part3
Let's make a book management web application with Spring Boot part2
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
[For beginners] Minimum sample to update RecyclerView with DiffUtils in Java
Sample code to unit test a Spring Boot controller with MockMvc
Spring Boot + Java + GitHub authentication login
Use Basic Authentication with Spring Boot
Build a Java project with Gradle
gRPC on Spring Boot with grpc-spring-boot-starter
Create an app with Spring Boot 2
Hot deploy with Spring Boot development
Database linkage with doma2 (Spring boot)