개발

[Java]Spring boot 본문

개인용 사이트 제작과정/Back-End

[Java]Spring boot

Study 2021. 12. 23. 15:30

프론트엔드와 연동

추가 Api들과 통신기능

 

Front-End: Thymeleaf

Back-End: Spring-Boot

DB: JPA, MySQL

 

 

 

build.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
buildscript{
    ext {
        springBootVersion = '2.4.4'
    }
 
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
 
// 스프링 필수 플러그인
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
 
group = 'com.SukhoAndHodu'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
 
repositories {
    mavenCentral()
}
 
dependencies {
    //스프링 부트, 롬복, h2 데이터베이스
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.projectlombok:lombok'
    implementation 'com.h2database:h2'
 
    //타임리프
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
 
    //mysql, spring jpa
    implementation 'mysql:mysql-connector-java'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
 
    //스프링 개발자툴
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
 
test {
    useJUnitPlatform()
}
cs

 

application.properties

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 서버 설정
server.port=8080
 
 
# spring static
spring.mvc.static-path-pattern=/static/**
spring.resources.static-location=classpath:/static/
spring.resources.add-mappings=true
spring.profiles.include=real-db
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57InnoDBDialect
spring.session.store-type=jdbc
 
# Mysql
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://{본인 mysql 주소}:3306/{ DB이름 }?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
spring.datasource.username={아이디}
spring.datasource.password={비밀번호}
 
# JPA
spring.jpa.hibernate.ddl-auto=create
spring.jpa.generate-ddl-auto=true
spring.jpa.show_sql = true
 
# Logging
logging.level.org.springframework.web=DEBUG
cs