Merge pull request #17797 from vpavic
* pr/17797: Harmonize Spring Session flush mode properties javadoc Add support for configuring Spring Session JDBC flush mode Closes gh-17797
This commit is contained in:
commit
3efead4ba5
|
|
@ -35,7 +35,8 @@ public class HazelcastSessionProperties {
|
|||
private String mapName = "spring:session:sessions";
|
||||
|
||||
/**
|
||||
* Sessions flush mode.
|
||||
* Sessions flush mode. Determines when session changes are written to the session
|
||||
* store.
|
||||
*/
|
||||
private FlushMode flushMode = FlushMode.ON_SAVE;
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ class JdbcSessionConfiguration {
|
|||
}
|
||||
setTableName(jdbcSessionProperties.getTableName());
|
||||
setCleanupCron(jdbcSessionProperties.getCleanupCron());
|
||||
setFlushMode(jdbcSessionProperties.getFlushMode());
|
||||
setSaveMode(jdbcSessionProperties.getSaveMode());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.session;
|
|||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
||||
import org.springframework.session.FlushMode;
|
||||
import org.springframework.session.SaveMode;
|
||||
|
||||
/**
|
||||
|
|
@ -56,6 +57,12 @@ public class JdbcSessionProperties {
|
|||
*/
|
||||
private DataSourceInitializationMode initializeSchema = DataSourceInitializationMode.EMBEDDED;
|
||||
|
||||
/**
|
||||
* Sessions flush mode. Determines when session changes are written to the session
|
||||
* store.
|
||||
*/
|
||||
private FlushMode flushMode = FlushMode.ON_SAVE;
|
||||
|
||||
/**
|
||||
* Sessions save mode. Determines how session changes are tracked and saved to the
|
||||
* session store.
|
||||
|
|
@ -94,6 +101,14 @@ public class JdbcSessionProperties {
|
|||
this.initializeSchema = initializeSchema;
|
||||
}
|
||||
|
||||
public FlushMode getFlushMode() {
|
||||
return this.flushMode;
|
||||
}
|
||||
|
||||
public void setFlushMode(FlushMode flushMode) {
|
||||
this.flushMode = flushMode;
|
||||
}
|
||||
|
||||
public SaveMode getSaveMode() {
|
||||
return this.saveMode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ public class RedisSessionProperties {
|
|||
private String namespace = "spring:session";
|
||||
|
||||
/**
|
||||
* Sessions flush mode.
|
||||
* Sessions flush mode. Determines when session changes are written to the session
|
||||
* store.
|
||||
*/
|
||||
private FlushMode flushMode = FlushMode.ON_SAVE;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
|||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.session.FlushMode;
|
||||
import org.springframework.session.SaveMode;
|
||||
import org.springframework.session.data.mongo.MongoOperationsSessionRepository;
|
||||
import org.springframework.session.data.redis.RedisOperationsSessionRepository;
|
||||
|
|
@ -130,6 +131,19 @@ class SessionAutoConfigurationJdbcTests extends AbstractSessionAutoConfiguration
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void customFlushMode() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.session.store-type=jdbc", "spring.session.jdbc.flush-mode=immediate")
|
||||
.run((context) -> {
|
||||
assertThat(context.getBean(JdbcSessionProperties.class).getFlushMode())
|
||||
.isEqualTo(FlushMode.IMMEDIATE);
|
||||
SpringBootJdbcHttpSessionConfiguration configuration = context
|
||||
.getBean(SpringBootJdbcHttpSessionConfiguration.class);
|
||||
assertThat(configuration).hasFieldOrPropertyWithValue("flushMode", FlushMode.IMMEDIATE);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void customSaveMode() {
|
||||
this.contextRunner
|
||||
|
|
|
|||
Loading…
Reference in New Issue