diff --git a/src/main/java/dongguk/osori/config/RedisConfig.java b/src/main/java/dongguk/osori/config/RedisConfig.java new file mode 100644 index 0000000..ab4be6d --- /dev/null +++ b/src/main/java/dongguk/osori/config/RedisConfig.java @@ -0,0 +1,29 @@ +package dongguk.osori.config; + +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.core.RedisTemplate; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; + +@Configuration +@EnableRedisHttpSession +public class RedisConfig { + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory("localhost", 6379); + } + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(redisConnectionFactory); + template.setKeySerializer(new StringRedisSerializer()); // Key를 String으로 직렬화 + template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); // Value를 JSON으로 직렬화 + return template; + } +} diff --git a/src/main/java/dongguk/osori/domain/user/UserController.java b/src/main/java/dongguk/osori/domain/user/UserController.java index 50c8bd1..11dad40 100644 --- a/src/main/java/dongguk/osori/domain/user/UserController.java +++ b/src/main/java/dongguk/osori/domain/user/UserController.java @@ -72,5 +72,4 @@ public ResponseEntity logout(HttpSession session) { } - } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4062363..540f597 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,6 @@ spring.datasource.url=jdbc:mysql://localhost:3306/osori spring.datasource.username=toni spring.datasource.password=1234 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # JPA spring.jpa.hibernate.ddl-auto=update @@ -12,17 +11,16 @@ spring.jpa.properties.hibernate.format_sql=true # Session spring.session.store-type=redis -spring.session.redis.namespace=osori:session - +spring.session.timeout=1800s # Redis -spring.redis.host=redis +spring.redis.host=localhost spring.redis.port=6379 spring.redis.password=1234 # Session Cookie Configuration server.servlet.session.cookie.name=JSESSIONID -# server.servlet.session.timeout=30m -# server.servlet.session.cookie.secure=true -# server.servlet.session.cookie.http-only=true - +# HTTPS ?? ? true? ?? +server.servlet.session.cookie.secure=false +server.servlet.session.cookie.http-only=true +server.servlet.session.timeout=30m