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
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".
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.
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