Class MongoIndexedSessionRepository
java.lang.Object
org.springframework.session.data.mongo.MongoIndexedSessionRepository
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationEventPublisherAware,FindByIndexNameSessionRepository<org.springframework.session.data.mongo.MongoSession>,SessionRepository<org.springframework.session.data.mongo.MongoSession>
public class MongoIndexedSessionRepository
extends Object
implements FindByIndexNameSessionRepository<org.springframework.session.data.mongo.MongoSession>, org.springframework.context.ApplicationEventPublisherAware, org.springframework.beans.factory.InitializingBean
Session repository implementation which stores sessions in Mongo. Uses
AbstractMongoSessionConverter to transform session objects from/to native Mongo
representation (DBObject). Repository is also responsible for removing expired
sessions from database. Cleanup is done every minute.- Since:
- 2.2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringthe default collection name for storing session.static final intDeprecated.Fields inherited from interface org.springframework.session.FindByIndexNameSessionRepository
PRINCIPAL_NAME_INDEX_NAME -
Constructor Summary
ConstructorsConstructorDescriptionMongoIndexedSessionRepository(org.springframework.data.mongodb.core.MongoOperations mongoOperations) -
Method Summary
Modifier and TypeMethodDescriptionvoidorg.springframework.session.data.mongo.MongoSessionCreates a newSessionthat is capable of being persisted by thisSessionRepository.voiddeleteById(String id) org.springframework.session.data.mongo.MongoSessionfindByIndexNameAndIndexValue(String indexName, String indexValue) Currently this repository allows only querying againstPRINCIPAL_NAME_INDEX_NAME.voidsave(org.springframework.session.data.mongo.MongoSession session) Ensures theSessioncreated bySessionRepository.createSession()is saved.voidsetApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher) voidsetCollectionName(String collectionName) voidsetDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval) Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated.voidsetMaxInactiveIntervalInSeconds(Integer defaultMaxInactiveInterval) Deprecated.since 3.0.0, in favor ofsetDefaultMaxInactiveInterval(Duration)voidsetMongoSessionConverter(AbstractMongoSessionConverter mongoSessionConverter) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.session.FindByIndexNameSessionRepository
findByPrincipalName
-
Field Details
-
DEFAULT_INACTIVE_INTERVAL
Deprecated.since 3.0.0 in favor ofMapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDSThe default time period in seconds in which a session will expire.- See Also:
-
DEFAULT_COLLECTION_NAME
the default collection name for storing session.- See Also:
-
-
Constructor Details
-
MongoIndexedSessionRepository
public MongoIndexedSessionRepository(org.springframework.data.mongodb.core.MongoOperations mongoOperations)
-
-
Method Details
-
createSession
public org.springframework.session.data.mongo.MongoSession createSession()Description copied from interface:SessionRepositoryCreates a newSessionthat is capable of being persisted by thisSessionRepository.This allows optimizations and customizations in how the
Sessionis persisted. For example, the implementation returned might keep track of the changes ensuring that only the delta needs to be persisted on a save.- Specified by:
createSessionin interfaceSessionRepository<org.springframework.session.data.mongo.MongoSession>- Returns:
- a new
Sessionthat is capable of being persisted by thisSessionRepository
-
save
public void save(org.springframework.session.data.mongo.MongoSession session) Description copied from interface:SessionRepositoryEnsures theSessioncreated bySessionRepository.createSession()is saved.Some implementations may choose to save as the
Sessionis updated by returning aSessionthat immediately persists any changes. In this case, this method may not actually do anything.- Specified by:
savein interfaceSessionRepository<org.springframework.session.data.mongo.MongoSession>- Parameters:
session- theSessionto save
-
findById
Description copied from interface:SessionRepository- Specified by:
findByIdin interfaceSessionRepository<org.springframework.session.data.mongo.MongoSession>- Parameters:
id- theSession.getId()to lookup- Returns:
- the
Sessionby theSession.getId()or null if noSessionis found.
-
findByIndexNameAndIndexValue
public Map<String,org.springframework.session.data.mongo.MongoSession> findByIndexNameAndIndexValue(String indexName, String indexValue) Currently this repository allows only querying againstPRINCIPAL_NAME_INDEX_NAME.- Specified by:
findByIndexNameAndIndexValuein interfaceFindByIndexNameSessionRepository<org.springframework.session.data.mongo.MongoSession>- Parameters:
indexName- the name if the index (i.e.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME)indexValue- the value of the index to search for.- Returns:
- sessions map
-
deleteById
Description copied from interface:SessionRepository- Specified by:
deleteByIdin interfaceSessionRepository<org.springframework.session.data.mongo.MongoSession>- Parameters:
id- theSession.getId()to delete
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
setApplicationEventPublisher
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher) - Specified by:
setApplicationEventPublisherin interfaceorg.springframework.context.ApplicationEventPublisherAware
-
setDefaultMaxInactiveInterval
Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated. A negative time indicates that the session will never time out. The default is 30 minutes.- Parameters:
defaultMaxInactiveInterval- the default maxInactiveInterval
-
setMaxInactiveIntervalInSeconds
@Deprecated(since="3.0.0") public void setMaxInactiveIntervalInSeconds(Integer defaultMaxInactiveInterval) Deprecated.since 3.0.0, in favor ofsetDefaultMaxInactiveInterval(Duration)Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated. A negative time indicates that the session will never time out. The default is 1800 (30 minutes).- Parameters:
defaultMaxInactiveInterval- the default maxInactiveInterval in seconds
-
setCollectionName
-
setMongoSessionConverter
-
MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS