티스토리 뷰
https://hawaii-demo-boot-jpa
다음은 인텔리제이(Intellij ) 개발환경에서 작업한 내용입니다.
또한 커뮤니티버전에서 설정시 일부 제약이 있을 수 있습니다.
Intellij 에서 프로젝트를 생성과정은 생략합니다.
근래에 자주 아래 에러가 발생하므로, 처음에 조치를 취하겠습니다.
<property name="dynamic.classpath" value="true" /> 를 카피해서
<component name="PropertiesComponent"> 아래 라인에 넣습니다.
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10'
}
group = 'com.chatbot..'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
compile group: 'com.h2database', name: 'h2', version: '1.4.200'
implementation 'org.springframework.boot:spring-boot-starter-web'
compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: '2.2.5.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.2.5.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web-services', version: '2.2.5.RELEASE'
annotationProcessor('org.projectlombok:lombok')
providedCompile group: 'org.projectlombok', name: 'lombok', version: '1.18.12'
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.5.4'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.2.5.RELEASE'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
compile group: 'com.querydsl', name: 'querydsl-jpa', version: '4.3.0'
compile group: 'com.querydsl', name: 'querydsl-apt', version: '4.3.0'
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.744'
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
def querydslSrcDir = 'src/main/generated'
querydsl{
library = 'com.querydsl:querydsl-apt'
jpa = true
querydslSourcesDir = querydslSrcDir
}
compileQuerydsl{
options.annotationProcessorPath = configurations.querydsl
}
configurations {
querydsl.extendsFrom compileClasspath
}
sourceSets{
main{
java{
srcDirs = ['src/main/java', querydslSrcDir]
}
}
}
|
cs |
application.yml
1
2
3
4
5
6
7
8
|
spring:
datasource:
url: jdbc:h2:mem:testdb;
driverClassName: org.h2.Driver
username: sa
password:
jpa:
database-platform: org.hibernate.dialect.H2Dialect
|
cs |
DatabaseConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
package com.parksrazor.web;
import org.h2.server.web.WebServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class DatabaseConfig {
@Bean
public ServletRegistrationBean h2servletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet());
registration.addUrlMappings("/console/*");
return registration;
}
}
|
cs |
엔티티 User 를 작성합니다.
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package com.parksrazor.web.user;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
@NoArgsConstructor(access=AccessLevel.PROTECTED)
@Getter
@ToString
@Entity
@Table(name= "users")
public class User {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id") private String userId;
@Column(name = "username") private String username;
@Column(name = "password") private String password;
@Column(name = "ssn") private String ssn;
@Column(name = "phone") private String phone;
@Column(name = "city") private String city;
@Column(name = "address") private String address;
@Column(name = "postalcode") private String postalcode;
@Column(name = "photo") private String photo;
@Column(name = "created_at") private Date createAt;
@Column(name = "updated_at") private Date updatedAt;
@Override
public String toString() {
return String.format("User[userId=%d, password='%s', username='%s']", userId, password, username);
}
@Builder
private User(String userId,
String password,
String userame,
String ssn,
String phone,
String city,
String address,
String postalcode,
String photo) {
this.userId = userId;
this.password = password;
this.username = username;
this.ssn = ssn;
this.phone = phone;
this.city = city;
this.address = address;
this.postalcode = postalcode;
this.photo = photo;
}
}
|
cs |
서버를 실행합니다.
브라우저에 http://localhost:8080/console/ 를 입력합니다.
Connect 를 실행하면 아래와 같이 만들어 진 것을 볼 수 있습니다.
코드 테스트를 실행합니다
jUnit5 버전으로 하겠습니다.
다음을 Gradle 의 Dependancy 내부에 넣습니다.
1
2
3
4
5
6
7
8
9
10
|
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testCompileOnly('junit:junit')
testRuntimeOnly('org.junit.vintage:junit-vintage-engine') {
because 'JUni 3 와 JUnit 4 테스트 실행을 위해 필요핟.'
}
|
cs |
File > Project Structure 로 진입합니다.
두번째 설정입니다.
jUnit 테스트 HelloWorld 입니다.
해당 내용은 이 블로그가 잘 정리돼있어서 그냥 참조로 진행합니다.
https://blog.naver.com/ssuyastory/221644575256
테스트를 위한 ProgressController 입니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
package com.chatbot.web.progress;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ProgressController {
@GetMapping("/")
public String helloWorld(){
return "TDD Success !! ";
}
}
|
cs |
결과값이 일치하면 아래와 같이 출력합니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package com.chatbot.web.progress;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class ProgressControllerTest {
@Autowired
ProgressController progressController;
@Test
void helloWorld() {
assertThat(progressController.helloWorld()).isEqualTo("TDD Success !! ");
}
}
|
cs |
결과값을 일부러 틀리게 작성하면 아래와 같이 Fail 을 표시합니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package com.chatbot.web.progress;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class ProgressControllerTest {
@Autowired
ProgressController progressController;
@Test
void helloWorld() {
assertThat(progressController.helloWorld()).isEqualTo("TDD Fail !!");
}
}
|
cs |
- Total
- Today
- Yesterday
- terms
- maven
- Django
- Mlearn
- FLASK
- JUnit
- COLAB
- intellij
- jQuery
- SpringBoot
- vscode
- React
- tensorflow
- Eclipse
- AWS
- mariadb
- Git
- ERD
- Mongo
- Algorithm
- Java
- Python
- Oracle
- springMVC
- SQLAlchemy
- database
- KAFKA
- docker
- JPA
- nodejs
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |