|
1 | 1 | /*
|
2 |
| - * Copyright 2014-2021 the original author or authors. |
| 2 | + * Copyright 2014-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package docs.http;
|
18 | 18 |
|
19 |
| -// import com.hazelcast.config.AttributeConfig; |
20 |
| -// import com.hazelcast.config.Config; |
21 |
| -// import com.hazelcast.config.IndexConfig; |
22 |
| -// import com.hazelcast.config.IndexType; |
23 |
| -// import com.hazelcast.config.SerializerConfig; |
24 |
| -// import com.hazelcast.core.Hazelcast; |
25 |
| -// import com.hazelcast.core.HazelcastInstance; |
26 |
| -// |
27 |
| -// import org.springframework.context.annotation.Bean; |
28 |
| -// import org.springframework.context.annotation.Configuration; |
29 |
| -// import org.springframework.session.MapSession; |
30 |
| -// import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; |
31 |
| -// import org.springframework.session.hazelcast.HazelcastSessionSerializer; |
32 |
| -// import org.springframework.session.hazelcast.PrincipalNameExtractor; |
33 |
| -// import |
34 |
| -// org.springframework.session.hazelcast.config.annotation.web.http.EnableHazelcastHttpSession; |
| 19 | +import com.hazelcast.config.AttributeConfig; |
| 20 | +import com.hazelcast.config.Config; |
| 21 | +import com.hazelcast.config.IndexConfig; |
| 22 | +import com.hazelcast.config.IndexType; |
| 23 | +import com.hazelcast.config.SerializerConfig; |
| 24 | +import com.hazelcast.core.Hazelcast; |
| 25 | +import com.hazelcast.core.HazelcastInstance; |
| 26 | + |
| 27 | +import org.springframework.context.annotation.Bean; |
| 28 | +import org.springframework.context.annotation.Configuration; |
| 29 | +import org.springframework.session.MapSession; |
| 30 | +import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; |
| 31 | +import org.springframework.session.hazelcast.HazelcastSessionSerializer; |
| 32 | +import org.springframework.session.hazelcast.PrincipalNameExtractor; |
| 33 | +import org.springframework.session.hazelcast.config.annotation.web.http.EnableHazelcastHttpSession; |
35 | 34 |
|
36 | 35 | // tag::config[]
|
37 |
| -// @EnableHazelcastHttpSession // <1> |
38 |
| -// @Configuration |
39 |
| -// public class HazelcastHttpSessionConfig { |
40 |
| -// |
41 |
| -// @Bean |
42 |
| -// public HazelcastInstance hazelcastInstance() { |
43 |
| -// Config config = new Config(); |
44 |
| -// AttributeConfig attributeConfig = new AttributeConfig() |
45 |
| -// .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) |
46 |
| -// .setExtractorClassName(PrincipalNameExtractor.class.getName()); |
47 |
| -// config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME) // <2> |
48 |
| -// .addAttributeConfig(attributeConfig).addIndexConfig( |
49 |
| -// new IndexConfig(IndexType.HASH, |
50 |
| -// HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); |
51 |
| -// SerializerConfig serializerConfig = new SerializerConfig(); |
52 |
| -// serializerConfig.setImplementation(new |
53 |
| -// HazelcastSessionSerializer()).setTypeClass(MapSession.class); |
54 |
| -// config.getSerializationConfig().addSerializerConfig(serializerConfig); // <3> |
55 |
| -// return Hazelcast.newHazelcastInstance(config); // <4> |
56 |
| -// } |
57 |
| -// |
58 |
| -// } |
| 36 | +@EnableHazelcastHttpSession // <1> |
| 37 | +@Configuration |
| 38 | +public class HazelcastHttpSessionConfig { |
| 39 | + |
| 40 | + @Bean |
| 41 | + public HazelcastInstance hazelcastInstance() { |
| 42 | + Config config = new Config(); |
| 43 | + AttributeConfig attributeConfig = new AttributeConfig() |
| 44 | + .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) |
| 45 | + .setExtractorClassName(PrincipalNameExtractor.class.getName()); |
| 46 | + config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME) // <2> |
| 47 | + .addAttributeConfig(attributeConfig).addIndexConfig( |
| 48 | + new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); |
| 49 | + SerializerConfig serializerConfig = new SerializerConfig(); |
| 50 | + serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class); |
| 51 | + config.getSerializationConfig().addSerializerConfig(serializerConfig); // <3> |
| 52 | + return Hazelcast.newHazelcastInstance(config); // <4> |
| 53 | + } |
| 54 | + |
| 55 | +} |
59 | 56 | // end::config[]
|
0 commit comments