"꾸준하고 완벽한 한 걸음"

Spring/Spring Security

개발자 유미 - 스프링 시큐리티 6. DB 연결

kimyoungrok 2025. 3. 7. 02:01
728x90

스프링 시큐리티 6 : DB 연결

 

개발자 유미 | 커뮤니티

 

개발자 유미 | 커뮤니티

 

www.devyummi.com

 


데이터베이스의 필요성

로그인한 사용자의 인증을 위해서는 회원 정보를 저장해야한다.

이를 위해서는 DB가 필요하며 JPA를 사용해 DB 쿼리문을 쉽게 생성할 수 있다.

build.gradle 설정

프로젝트에 MySQL 및 JAP 의존성을 추가 후 리프레쉬 후 필요한 파일을 다운받고 활성화를 해주자.

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    runtimeOnly 'com.mysql:mysql-connector-j'
}

application.properties 설정

스프링 서버에서 DB에 접속할 수 있도록 정보를 입력해주자.

spring.application.name=testsecurity
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/
spring.datasource.username=root
spring.datasource.password=admin
728x90