Polish JacksonMongoSessionConverter
Issue gh-416
This commit is contained in:
@@ -82,6 +82,8 @@ include::{samples-dir}mongo/src/main/java/sample/config/HttpSessionConfig.java[t
|
||||
The filter is what is in charge of replacing the `HttpSession` implementation to be backed by Spring Session.
|
||||
In this instance Spring Session is backed by Mongo.
|
||||
|
||||
<2> We explicitly configure `JdkMongoSessionConverter` since Spring Security's objects cannot be automatically persisted using Jackson (the default if Jackson is on the classpath).
|
||||
|
||||
// end::config[]
|
||||
|
||||
[[boot-mongo-configuration]]
|
||||
|
||||
@@ -15,10 +15,17 @@
|
||||
*/
|
||||
package sample.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.session.data.mongo.JdkMongoSessionConverter;
|
||||
import org.springframework.session.data.mongo.config.annotation.web.http.EnableMongoHttpSession;
|
||||
|
||||
// tag::class[]
|
||||
@EnableMongoHttpSession // <1>
|
||||
public class HttpSessionConfig {
|
||||
|
||||
@Bean
|
||||
public JdkMongoSessionConverter jdkMongoSessionConverter() {
|
||||
return new JdkMongoSessionConverter(); // <2>
|
||||
}
|
||||
}
|
||||
// end::class[]
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.session.Session;
|
||||
* @author Jakub Kubrynski
|
||||
* @since 1.2
|
||||
*/
|
||||
class JdkMongoSessionConverter extends AbstractMongoSessionConverter {
|
||||
public class JdkMongoSessionConverter extends AbstractMongoSessionConverter {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(JdkMongoSessionConverter.class);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
@@ -55,7 +56,8 @@ public class MongoOperationsSessionRepository
|
||||
|
||||
private final MongoOperations mongoOperations;
|
||||
|
||||
private AbstractMongoSessionConverter mongoSessionConverter = SessionConverterProvider.get();
|
||||
private AbstractMongoSessionConverter mongoSessionConverter = SessionConverterProvider
|
||||
.getDefaultMongoConverter();
|
||||
private Integer maxInactiveIntervalInSeconds = DEFAULT_INACTIVE_INTERVAL;
|
||||
private String collectionName = DEFAULT_COLLECTION_NAME;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ final class SessionConverterProvider {
|
||||
private SessionConverterProvider() {
|
||||
}
|
||||
|
||||
static AbstractMongoSessionConverter get() {
|
||||
static AbstractMongoSessionConverter getDefaultMongoConverter() {
|
||||
if (ClassUtils.isPresent(JACKSON_CLASS_NAME, null)) {
|
||||
return new JacksonMongoSessionConverter();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user