Merge branch '1.5.x'
This commit is contained in:
commit
2f57e1885a
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -47,9 +47,9 @@ public abstract class AbstractSessionAutoConfigurationTests {
|
|||
|
||||
protected <T extends SessionRepository<?>> T validateSessionRepository(
|
||||
Class<T> 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) {
|
||||
|
|
|
@ -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.<Class<?>>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.<Class<?>>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.<Class<?>>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<Object, Object> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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.<Class<?>>singletonList(HazelcastConfiguration.class),
|
||||
"spring.session.store-type=hazelcast");
|
||||
validateSessionRepository(HazelcastSessionRepository.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hazelcastSessionStoreWithCustomizations() {
|
||||
load(Collections.<Class<?>>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<Object, Object> map = mock(IMap.class);
|
||||
HazelcastInstance mock = mock(HazelcastInstance.class);
|
||||
given(mock.getMap("foo:bar:biz")).willReturn(map);
|
||||
return mock;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<activemq.version>5.13.4</activemq.version>
|
||||
<antlr2.version>2.7.7</antlr2.version>
|
||||
<appengine.version>1.9.44</appengine.version>
|
||||
<artemis.version>1.4.0</artemis.version>
|
||||
<artemis.version>1.5.0</artemis.version>
|
||||
<aspectj.version>1.8.9</aspectj.version>
|
||||
<assertj.version>2.5.0</assertj.version>
|
||||
<atomikos.version>3.9.3</atomikos.version>
|
||||
|
@ -161,7 +161,7 @@
|
|||
<spring-security.version>4.2.0.RELEASE</spring-security.version>
|
||||
<spring-security-jwt.version>1.0.5.RELEASE</spring-security-jwt.version>
|
||||
<spring-security-oauth.version>2.0.12.RELEASE</spring-security-oauth.version>
|
||||
<spring-session.version>1.3.0.M2</spring-session.version>
|
||||
<spring-session.version>1.3.0.RC1</spring-session.version>
|
||||
<spring-social.version>1.1.4.RELEASE</spring-social.version>
|
||||
<spring-social-facebook.version>2.0.3.RELEASE</spring-social-facebook.version>
|
||||
<spring-social-linkedin.version>1.0.2.RELEASE</spring-social-linkedin.version>
|
||||
|
@ -2134,11 +2134,6 @@
|
|||
<artifactId>spring-session-data-gemfire</artifactId>
|
||||
<version>${spring-session.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.session</groupId>
|
||||
<artifactId>spring-session-data-geode</artifactId>
|
||||
<version>${spring-session.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.session</groupId>
|
||||
<artifactId>spring-session-data-mongo</artifactId>
|
||||
|
@ -2535,4 +2530,4 @@
|
|||
<id>integration-test</id>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in New Issue