Environment construction and Hello World take 90% of the development time, so I created an article to solve it.
MacOS Mojave 10.14.3
Eclipse 4.11.0
Gradle 5.5
I will omit the JDK and Eclipse because I think they will come out if I google.
If you set the JDK version to 10 or 9, it may not work, so I think you should set it to about 8.
Install the latest version of Eclipse. I dropped Japanese.
The template is easy, so use Spring Initializr.
Of course you can do it from Eclipse, but
At first you will be worried about dependencies, so it is better to do it with GUI first from articles that are likely to be used to some extent on the net. I do not think.
For the time being, select Gradle, the language is Java, and the Spring Boot version can be left as it is.
Group is the root package name. You don't have to think so deeply. This time it was com.p0ngch4ng.labo.
Artifact is the project name. Give it a name for what you want to make.
Dependencies are dependencies. Since you can add it later, add only JPA, MySQL, and Web at first.
If you open the dropped zip, it will look like this.
Import this into Eclipse if there is nothing missing.
Select an existing Grale project and unzip the downloaded zip file
Select as the project root directory. After that, hit the next one repeatedly.
Then, I think that the project can be developed like this.
At this point, the project is ready for the time being.
All you have to do is start from here.
~~ I probably chose MySQL as a dependency, but I didn't specify the database in Build.Gradle [^ 1] ~~ You can set it up as it is, but if you have never touched SQL or want to execute it for the time being, I would like to execute it without annoying settings.
Therefore,
implementation 'org.hsqldb:hsqldb:2.3.2'
Let's add this one sentence to Gradle.build
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.p0ngch4ng'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
tasks.withType(AbstractCompile)*.options*.encoding = 'UTF-8'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
//Add here!
//
implementation 'org.hsqldb:hsqldb:2.3.2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
If you add it, it will not be updated as it is, so right-click on the project and select Gradle → Refresh Dependencies. [^ 2]
By doing this, it will refer to the database without any special settings, so if you do not touch the database, you should be able to do Hello World with this.
Below 2019/8/5 postscript
The above method is just a method of initial setting, and I think that MySQL etc. are often used when actually developing.
compile("mysql:mysql-connector-java")
//implementation 'org.hsqldb:hsqldb:2.3.2'
So rewrite build.gradle like this: If nothing is done, an error will occur, so Create a database. I will omit the setup of MYSQL here.
In addition, create a file called ʻapplication.properties in
src / main / resouces` and write as follows.
spring.thymeleaf.cache=false
spring.datasource.url=jdbc:mysql://localhost:3306/{My database name}?characterEncoding=UTF-8&serverTimezone=JST
spring.datasource.username={User name}
spring.datasource.password={password}
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.jpa.database=MYSQL
spring.jpa.hibernate.ddl-auto=update
Safe, Hello World.
Recommended Posts