Springboot 초기설정

minm·2024년 2월 1일

build.graddle

implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
developmentOnly 'org.springframework.boot:spring-boot-devtools'

lombok 프레임워크 설치

build.graddle

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

마리아DB 설치

build.graddle

implementation 'org.mariadb.jdbc:mariadb-java-client:2.7.4'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

마리아DB 연동

application.properties

#DATABASE
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.url=jdbc:mariadb://localhost:3306/MusicCharts 
<- 3306번 포트의 MusicCharts 데이터베이스 연동
spring.datasource.username=root <-사용자명
spring.datasource.password=★★★★★ <- DB 비밀번호

#JPA
spring.jpa.hibernate.ddl-auto=update
spring.jpa.open-in-view=false 
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.show-sql=true

템플릿 설치 (HTML)

build.graddle

implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'

템플릿 파일은 리소스 폴더 내부에 Templates 패키지 안에 .html 파일로 생성하면 된다. 다른 css나 js는 static 폴더에서 생성하며, 따로 html과 연결해주어야 한다.

<link rel="stylesheet" type="text/css" th:href="@{/css/LR_styles.css}">
<script src="/JS/LR.js"></script>

웹소켓 설치

build.graddle

implementation 'org.springframework.boot:spring-boot-starter-websocket'
<script src="https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.5.1/sockjs.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"></script>

이 코드는 웹 소켓(WebSocket)을 사용하는 라이브러리인 SockJS와 STOMP를 로드하는데 사용된다. 웹 소켓은 실시간 양방향 통신을 지원하는 프로토콜이며, SockJS와 STOMP는 웹 소켓을 브라우저에서 더 쉽게 사용할 수 있도록 도와주는 라이브러리이다.

springsecurity 설치

build.graddle

implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'

0개의 댓글