It's been almost a year and a half since I changed jobs to an engineer, so it's about time I started thinking that I should be able to develop basic apps with Java and Spring Boot. The reference book I am currently using is Introduction to Spring Boot 2 Programming. I haven't been able to practice everything while moving my hands yet, but I've done it until I created a simple app, so I will summarize it. It was a good study because I created it with my own original code in some places. I would like to write it after reviewing it in several parts.
github: https://github.com/noydmt/myboot
First, from the explanation of the tools and FW used.
Gradle
Build tool by Groovy
.
Build information and processing is described in Groovy
. Groovy
is a kind of programming language that can be written with a grammar that follows Java
, and you can also create apps. In addition to the description of Gradle
, it is often used when making a prototype before full-scale application development.
Unlike maven
, pom.xml
is not used, and the build.gradle
file is placed in the project to manage the environment.
When creating a project with STS, it is necessary to install a plug-in tool dedicated to gradle in advance, and it seems that you often start with STS, so Help
=> Eclipse Marketplace
=> " Buildship You can create a gradle project by installing
=> Buildship gradle integration
.
Thymeleaf
A template library made for Java. Since it is built into Spring Boot by default, there is no need to install any libraries. It is possible to display the screen using th
or$ {}
, which does not affect HTML unlike JSP. To be honest, in my personal opinion, I don't think the taste of learning a template engine is that great.
SpringBoot
A Java framework that is further extended based on the Spring
framework. Its strength is that it can be developed at high speed like rails.
Like the Spring framework
, it also has DI, so there is no need to bother to create an instance of the class you want to use in the dependent class. I searched for AOP
, but I'm not sure.
Next, I will introduce the environment actually used in application development.
build.gradle
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.gradle.springboot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.hsqldb:hsqldb')
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
If you take a quick look at the contents, plugins
, repositories
, and dependencies
are the components of this file. In plugins
, the languages used such as Java
, springBoot
, and dependency
are used. Frameworks, management tools, versions, etc. are managed.
Please note that the functions that can be used may be limited depending on the version.
That said, it is the dependencies
that individual developers are more likely to mess with.
With this dependencies
, you just need to describe in advance what kind of library you want to use, and it will download it at build time.
If there is a library you want to use without using build.gradle
, you can't use it without downloading the jar file from the outside and passing it through the classpath, but gradle
uses the library without such trouble. You can do it.
The library I used this time is as follows. ・ Spring Boot ・ Thymeleaf · HSQLDB ・ JPA
HSQLDB allows you to embed a DB inside a Java application and can store the database in memory instead of on the original server. Often used as a development test database. Since it is stored in memory, it is volatile, and once the record is stored, it disappears when the application is restarted.
JPA is an OR mapper that can realize RDB table operations more easily by using entity classes.
Continue to next time. .. ..
Recommended Posts