diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HazelcastSessionConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HazelcastSessionConfiguration.java index 09331e224a0..9dc6d56bdaf 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HazelcastSessionConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/HazelcastSessionConfiguration.java @@ -32,6 +32,7 @@ import org.springframework.session.hazelcast.config.annotation.web.http.Hazelcas * @author Tommy Ludwig * @author EddĂș MelĂ©ndez * @author Stephane Nicoll + * @author Vedran Pavic */ @Configuration @ConditionalOnMissingBean(SessionRepository.class) @@ -49,7 +50,9 @@ class HazelcastSessionConfiguration { if (timeout != null) { setMaxInactiveIntervalInSeconds(timeout); } - setSessionMapName(sessionProperties.getHazelcast().getMapName()); + SessionProperties.Hazelcast hazelcast = sessionProperties.getHazelcast(); + setSessionMapName(hazelcast.getMapName()); + setHazelcastFlushMode(hazelcast.getFlushMode()); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionProperties.java index 0bee9e635a9..fc83b3f5958 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionProperties.java @@ -20,6 +20,7 @@ import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.session.data.redis.RedisFlushMode; +import org.springframework.session.hazelcast.HazelcastFlushMode; /** * Configuration properties for Spring Session. @@ -92,6 +93,11 @@ public class SessionProperties { */ private String mapName = "spring:session:sessions"; + /** + * Sessions flush mode. + */ + private HazelcastFlushMode flushMode = HazelcastFlushMode.ON_SAVE; + public String getMapName() { return this.mapName; } @@ -100,6 +106,14 @@ public class SessionProperties { this.mapName = mapName; } + public HazelcastFlushMode getFlushMode() { + return this.flushMode; + } + + public void setFlushMode(HazelcastFlushMode flushMode) { + this.flushMode = flushMode; + } + } public static class Jdbc { @@ -194,7 +208,7 @@ public class SessionProperties { private String namespace = ""; /** - * Flush mode for the Redis sessions. + * Sessions flush mode. */ private RedisFlushMode flushMode = RedisFlushMode.ON_SAVE; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java index dd8106e2fef..2d589660a43 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java @@ -47,9 +47,9 @@ public abstract class AbstractSessionAutoConfigurationTests { protected > T validateSessionRepository( Class type) { - SessionRepository cacheManager = this.context.getBean(SessionRepository.class); - assertThat(cacheManager).as("Wrong session repository type").isInstanceOf(type); - return type.cast(cacheManager); + SessionRepository repository = this.context.getBean(SessionRepository.class); + assertThat(repository).as("Wrong session repository type").isInstanceOf(type); + return type.cast(repository); } protected Integer getSessionTimeout(SessionRepository sessionRepository) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java new file mode 100644 index 00000000000..8c2674f855a --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java @@ -0,0 +1,92 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.session; + +import java.util.Collections; + +import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.IMap; +import org.junit.Test; + +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.session.hazelcast.HazelcastFlushMode; +import org.springframework.session.hazelcast.HazelcastSessionRepository; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * Hazelcast specific tests for {@link SessionAutoConfiguration}. + * + * @author Vedran Pavic + */ +public class SessionAutoConfigurationHazelcastTests + extends AbstractSessionAutoConfigurationTests { + + @Test + public void defaultConfig() { + load(Collections.>singletonList(HazelcastConfiguration.class), + "spring.session.store-type=hazelcast"); + validateSessionRepository(HazelcastSessionRepository.class); + HazelcastInstance hazelcastInstance = this.context + .getBean(HazelcastInstance.class); + verify(hazelcastInstance, times(1)).getMap("spring:session:sessions"); + } + + @Test + public void customMapName() { + load(Collections.>singletonList(HazelcastConfiguration.class), + "spring.session.store-type=hazelcast", + "spring.session.hazelcast.map-name=foo:bar:biz"); + validateSessionRepository(HazelcastSessionRepository.class); + HazelcastInstance hazelcastInstance = this.context + .getBean(HazelcastInstance.class); + verify(hazelcastInstance, times(1)).getMap("foo:bar:biz"); + } + + @Test + public void customFlushMode() { + load(Collections.>singletonList(HazelcastConfiguration.class), + "spring.session.store-type=hazelcast", + "spring.session.hazelcast.flush-mode=immediate"); + HazelcastSessionRepository repository = validateSessionRepository( + HazelcastSessionRepository.class); + assertThat(new DirectFieldAccessor(repository).getPropertyValue( + "hazelcastFlushMode")).isEqualTo(HazelcastFlushMode.IMMEDIATE); + } + + @Configuration + static class HazelcastConfiguration { + + @Bean + @SuppressWarnings("unchecked") + public HazelcastInstance hazelcastInstance() { + IMap map = mock(IMap.class); + HazelcastInstance mock = mock(HazelcastInstance.class); + given(mock.getMap("spring:session:sessions")).willReturn(map); + given(mock.getMap("foo:bar:biz")).willReturn(map); + return mock; + } + + } + +} diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java index 812d76721c7..788ce036400 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java @@ -19,9 +19,6 @@ package org.springframework.boot.autoconfigure.session; import java.util.Arrays; import java.util.Collections; -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -37,13 +34,8 @@ import org.springframework.session.ExpiringSession; import org.springframework.session.MapSessionRepository; import org.springframework.session.SessionRepository; import org.springframework.session.data.mongo.MongoOperationsSessionRepository; -import org.springframework.session.hazelcast.HazelcastSessionRepository; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; /** * Tests for {@link SessionAutoConfiguration}. @@ -105,24 +97,7 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat } @Test - public void hazelcastSessionStore() { - load(Collections.>singletonList(HazelcastConfiguration.class), - "spring.session.store-type=hazelcast"); - validateSessionRepository(HazelcastSessionRepository.class); - } - - @Test - public void hazelcastSessionStoreWithCustomizations() { - load(Collections.>singletonList(HazelcastSpecificMap.class), - "spring.session.store-type=hazelcast", - "spring.session.hazelcast.map-name=foo:bar:biz"); - validateSessionRepository(HazelcastSessionRepository.class); - HazelcastInstance hazelcastInstance = this.context - .getBean(HazelcastInstance.class); - verify(hazelcastInstance, times(1)).getMap("foo:bar:biz"); - } - - @Test + @SuppressWarnings("unchecked") public void mongoSessionStore() { load(Arrays.asList(EmbeddedMongoAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class), @@ -131,6 +106,7 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat } @Test + @SuppressWarnings("unchecked") public void mongoSessionStoreWithCustomizations() { load(Arrays.asList(EmbeddedMongoAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class), @@ -161,28 +137,4 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat } - @Configuration - static class HazelcastConfiguration { - - @Bean - public HazelcastInstance hazelcastInstance() { - return Hazelcast.newHazelcastInstance(); - } - - } - - @Configuration - static class HazelcastSpecificMap { - - @Bean - @SuppressWarnings("unchecked") - public HazelcastInstance hazelcastInstance() { - IMap map = mock(IMap.class); - HazelcastInstance mock = mock(HazelcastInstance.class); - given(mock.getMap("foo:bar:biz")).willReturn(map); - return mock; - } - - } - } diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 73a4da5146d..f41c15cb027 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -46,7 +46,7 @@ 5.13.4 2.7.7 1.9.44 - 1.4.0 + 1.5.0 1.8.9 2.5.0 3.9.3 @@ -161,7 +161,7 @@ 4.2.0.RELEASE 1.0.5.RELEASE 2.0.12.RELEASE - 1.3.0.M2 + 1.3.0.RC1 1.1.4.RELEASE 2.0.3.RELEASE 1.0.2.RELEASE @@ -2134,11 +2134,6 @@ spring-session-data-gemfire ${spring-session.version} - - org.springframework.session - spring-session-data-geode - ${spring-session.version} - org.springframework.session spring-session-data-mongo @@ -2535,4 +2530,4 @@ integration-test - \ No newline at end of file + diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index a91d04870bb..562f9fc913d 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -374,12 +374,13 @@ content into your application; rather pick only the properties that you need. spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/ # Locations of static resources. # SPRING SESSION ({sc-spring-boot-autoconfigure}/session/SessionProperties.{sc-ext}[SessionProperties]) + spring.session.hazelcast.flush-mode= # Sessions flush mode. spring.session.hazelcast.map-name=spring:session:sessions # Name of the map used to store sessions. spring.session.jdbc.initializer.enabled= # Create the required session tables on startup if necessary. Enabled automatically if the default table name is set or a custom schema is configured. spring.session.jdbc.schema=classpath:org/springframework/session/jdbc/schema-@@platform@@.sql # Path to the SQL file to use to initialize the database schema. spring.session.jdbc.table-name=SPRING_SESSION # Name of database table used to store sessions. spring.session.mongo.collection-name=sessions # Collection name used to store sessions. - spring.session.redis.flush-mode= # Flush mode for the Redis sessions. + spring.session.redis.flush-mode= # Sessions flush mode. spring.session.redis.namespace= # Namespace for keys used to store sessions. spring.session.store-type= # Session store type.