Server Session
- Servlet container (e.g. Tomcat, Jetty) managed sessions
Configuration
server:
servlet:
session:
timeout: 1800s
cookie:
max-age: 15m
http-only: true
secure: true
Spring Session
- Spring Session provides an API and implementations for managing a user’s session information.
- Provides the ability to persist session information in external session stores
- redis, jdbc 같은 저장소 이용가능
configuration
spring:
session:
timeout: 1m
redis:
namespace: spring:session
data:
redis:
host: 192.168.0.16
port: 6379
gradle
dependencies{
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.session:spring-session-data-redis'
}
application.yaml
spring:
redis:
host: localhost
port: 6379
session:
store-type: redis
SessionConfig
@Configuration
@EnableRedisHttpSession
public class SessionConfig {
}
Stateless
application.yaml
server:
servlet:
session:
enabled: false
persistence: none
spring security 를 사용하는 경우
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
}
}