Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
Redis 적용(Session 처리) (#14)
Browse files Browse the repository at this point in the history
* Add Redis적용 (세션처리)

#12

* Add 세션처리 관련 라이브러리 추가

* Fix 중복된 Redis 설정값 제거

Co-authored-by: qzqz0826 <qzqz0826@cavuai.com>
  • Loading branch information
phantom08266 and juneheelee committed May 13, 2021
1 parent 3373167 commit 77fbdcf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.4.3'
//javax.annotation.meta.When 경고로 인해 구글에서 해당 버그 수정한 의존성 추가
implementation 'com.google.code.findbugs:jsr305:3.0.2'
// Redis 세션 적용하기위한 의존성 추가
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis'
implementation group: 'org.springframework.session', name: 'spring-session-data-redis'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/dev/careers/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.dev.careers.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;

@Configuration
@EnableRedisRepositories
public class RedisConfig {

@Value("${spring.redis.host}")
private String redisHost;

@Value("${spring.redis.port}")
private int redisProt;

@Bean
public RedisConnectionFactory redisConnectionFactory(){
return new LettuceConnectionFactory(redisHost,redisProt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.dev.careers.service.error.ViolationException;
import java.util.Optional;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Component;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

@Component
@EnableRedisHttpSession
public class SessionAuthenticator {

public final static String SESSION_NAME = "userID";
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ server.servlet.session.timeout=3600

logging:
config: classpath:log4j2.xml

spring.redis.host=localhost
spring.redis.port=6379

0 comments on commit 77fbdcf

Please sign in to comment.