In my previous blog I’ve explained spring-session grails plugin along with Redis datastore. We’ve also covered JSON serialization that will be almost same when you use mongo datastore. In this blog post I’ll explain how you can use MongoDB as your session store.
要更改数据存储区,您需要在配置槽。
springsession.sessionStore=SessionStore.MONGO
这会将MongoDB设置为您的数据存储。 默认情况下,它将尝试连接正在运行的mongo本地主机港口27017。 我们来看看一些配置属性及其默认值。
注意:Someofthecommonpropertiesexplainedinpreviousblock。Thosewillworksameformongodatastore。
springsession.mongo.hostName="localhost" // MongoDB host server. Default is localhost.
springsession.mongo.port=27017 // MongoDB port. Default is 27017.
springsession.mongo.database="spring-session" // MongoDB database to store sessions. Default is spring-session.
springsession.mongo.username="" // MongoDB username. Default is "".
springsession.mongo.password="" // MongoDB password. Default is "".
springsession.mongo.collectionName="sessions" // Mongo collection name to store session data. Default is "sessions".
springsession.mongo.replicaSet=[[:] ] // MongoDB replica set if any. It includes list of maps [[hostName: 'localhost', port: 27017] ] Default is [[:]].
springsession.mongo.jackson.modules=[] // Jackson module class if any. Default is empty list
注意:MongoDBisaNoSQLandschemalessdatabase.Soyoudon’tneedtocreatedatabaseandcollectionsforthesession.It’llautocreatedwhensessionwillcreated.
By default it uses Java serialization. To use JSON Serialization please visit to first blog of this series. First 2 steps will be same but in 3rd step Register my module class with spring-session plugin you will have to use mongo specific jackson.modules
property.
springsession.mongo.jackson.modules = ['demo.SimpleModule']
就是这个帖子。 在下一个博客中,我将说明如何将JDBC数据存储区与spring-session grails插件一起使用。