Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 게시판 작성자를 아이디로
- msa
- 공백검사
- JPA
- 자바스크립트
- 유효성검사
- 중복되지 않는 값 만들기
- 관계형 데이터베이스
- spring security
- ORM
- 스프링 시큐리티
- Thymeleaf
- UUID
- 모던 자바스크립트 Deep Dive
- 자바
- java
- 출처 모던 자바스크립트 Deep Dive
- 자바 ORM 표준 JPA 프로그래밍
Archives
- Today
- Total
인지용
스프링부트 초반 셋팅 방법 본문
방금 막 스프링 부트 프로젝트를 만들었을 때
build.gradle 및 기본적인 셋팅 하는 방법을 알아보겠습니다.
사용할 기술 스택
- JAVA11
- Spring Data Jpa
- Spring Security
- Querydsl
- Junit5
- Thymeleaf
- Mysql
build.gradle 설정
숫자를 적어놓은건 Querydsl 설정입니다.
- (1) querydsl 플러그인을 추가합니다.
- (2) querydsl dependency
- (3) Q클래스 생성을 위한 라이브러리 dependency
- (4) Q클래스가 생성될 프로젝트 경로를 변수로 지정
- (5) querydsl 설정. JPA사용 여부와 Q클래스 사용할 경로 지정
- (6) build시 사용할 sourceSet을 추가
- (7) querydsl이 compileClassPath를 상속하도록 설정
- (8) querydsl이 컴파일시 사용할 옵션 설정
- (9), (10) Q클래스가 이미 존재할 경우 삭제 후 다시 생성하도록 설정
( 9, 10번은 없어도 상관없습니다. )
( 9, 10번 설정이 없으면 나중에 Travis CI를 통한 배포 자동화 시 Q클래스 문제가 생겨서 배포가 안되더라고요. )
build.gradle 전체 코드
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
id 'java'
}
group = 'bbBlog'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
implementation 'com.querydsl:querydsl-jpa:5.0.0'
implementation 'com.querydsl:querydsl-apt:5.0.0'
runtimeOnly 'mysql:mysql-connector-java'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
tasks.named('test') {
useJUnitPlatform()
}
def querydslDir = "src/main/generated"
querydsl {
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir(querydslDir)
}
configurations {
querydsl.extendsFrom(compileClasspath)
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
compileQuerydsl.doFirst {
if(file(querydslDir).exists()) delete(file(querydslDir))
}
compileJava.doFirst {
if(file(querydslDir).exists()) delete(file(querydslDir))
}
group과 querydslDir의 값만 본인의 프로젝트에 맞게 변경하면 될 것 같습니다.
JPA 설정
@EnableJpaAuditing 어노테이션을 사용함으로써 Auditing 기능을 활성화하는 것입니다.
Auditing는 가볍게 설명하면
JPA에서 시간에 대해서 자동으로 값을 넣어주는 기능입니다.
applicaiton.yml 설정
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/databaseName
username: username
password: password
devtools:
livereload:
enabled: true
jpa:
open-in-view: false
show-sql: true
hibernate:
ddl-auto: none
properties:
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
hibernate:
format_sql: true
mvc:
hiddenmethod:
filter:
enabled: true
logging:
level:
org:
springframework : INFO
spring
datasource : 데이터베이스 관련 설정
- driver-class-name : 사용할 JDBC 드라이버 클래스 이름
- url : 데이터베이스의 JDBC URL
- username : 데이터베이스의 사용자 아이디
- password : 데이터베이스의 사용자 비밀번호
devtools
- livereload.enabled : livereload 사용 여부 ( 웹브라우저 자동 새로고침 프로그램 ) ( 기본 true )
jpa
- database-platform : 사용할 데이터베이스 이름
- open-in-view : 영속성 컨텍스트를 뷰까지 열어두는 기능 ( 기본 true )
- hibernate.show-sql : 사용되는 쿼리 콘솔에 보여주기 ( 기본 false )
- hibernate.ddl-auto : 서버 재시작 시 테이블 어떻게 할지 ( create : 테이블 삭제 후 새로 생성, update : 테이블 유지, 새로운 필드 추가. 삭제는 불가능 ) ( 기본값 없음 )
- properties.hibernate.format_sql : sql을 보기 좋게 해 줌
mvc
- hiddenmethod.filter.enabled : Spring의 HiddenHttpMethodFilter 활성화 여부 ( 기본 false )
logging
- level.org.springframework : 표시할 로그 레벨 설정 ( INFO보다 하위 레벨의 로그 레벨은 표시하지 않음 )
.gitignore 설정
*.yml
*.properties
.DS_Store
추가
출처
https://jaime-note.tistory.com/67
https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html
'정보들' 카테고리의 다른 글
Mysql load data local infile 방법 대용량 인서트 (0) | 2022.01.26 |
---|---|
자바 is a 관계와(상속관계) has a 관계(포함관계) (0) | 2022.01.21 |
메모리란 (0) | 2021.08.27 |
java UUID란 (0) | 2021.08.25 |
java MultiValueMap 이란 (0) | 2021.08.24 |