Skip to content

Fix deprecation warnings in Spring Session auto-configuration #32633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ SessionRepositoryCustomizer<HazelcastIndexedSessionRepository> springBootSession
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
return (sessionRepository) -> {
map.from(sessionProperties.determineTimeout(() -> serverProperties.getServlet().getSession().getTimeout()))
.to((timeout) -> sessionRepository.setDefaultMaxInactiveInterval((int) timeout.getSeconds()));
.to(sessionRepository::setDefaultMaxInactiveInterval);
map.from(hazelcastSessionProperties::getMapName).to(sessionRepository::setSessionMapName);
map.from(hazelcastSessionProperties::getFlushMode).to(sessionRepository::setFlushMode);
map.from(hazelcastSessionProperties::getSaveMode).to(sessionRepository::setSaveMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ SessionRepositoryCustomizer<JdbcIndexedSessionRepository> springBootSessionRepos
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
return (sessionRepository) -> {
map.from(sessionProperties.determineTimeout(() -> serverProperties.getServlet().getSession().getTimeout()))
.to((timeout) -> sessionRepository.setDefaultMaxInactiveInterval((int) timeout.getSeconds()));
.to(sessionRepository::setDefaultMaxInactiveInterval);
map.from(jdbcSessionProperties::getTableName).to(sessionRepository::setTableName);
map.from(jdbcSessionProperties::getFlushMode).to(sessionRepository::setFlushMode);
map.from(jdbcSessionProperties::getSaveMode).to(sessionRepository::setSaveMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ReactiveSessionRepositoryCustomizer<ReactiveMongoSessionRepository> springBootSe
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
return (sessionRepository) -> {
map.from(sessionProperties.determineTimeout(() -> serverProperties.getReactive().getSession().getTimeout()))
.to((timeout) -> sessionRepository.setMaxInactiveIntervalInSeconds((int) timeout.getSeconds()));
.to(sessionRepository::setDefaultMaxInactiveInterval);
map.from(mongoSessionProperties::getCollectionName).to(sessionRepository::setCollectionName);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SessionRepositoryCustomizer<MongoIndexedSessionRepository> springBootSessionRepo
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
return (sessionRepository) -> {
map.from(sessionProperties.determineTimeout(() -> serverProperties.getServlet().getSession().getTimeout()))
.to((timeout) -> sessionRepository.setMaxInactiveIntervalInSeconds((int) timeout.getSeconds()));
.to(sessionRepository::setDefaultMaxInactiveInterval);
map.from(mongoSessionProperties::getCollectionName).to(sessionRepository::setCollectionName);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ReactiveSessionRepositoryCustomizer<ReactiveRedisSessionRepository> springBootSe
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
return (sessionRepository) -> {
map.from(sessionProperties.determineTimeout(() -> serverProperties.getReactive().getSession().getTimeout()))
.to((timeout) -> sessionRepository.setDefaultMaxInactiveInterval((int) timeout.getSeconds()));
.to(sessionRepository::setDefaultMaxInactiveInterval);
map.from(redisSessionProperties::getNamespace).to(sessionRepository::setRedisKeyNamespace);
map.from(redisSessionProperties::getSaveMode).to(sessionRepository::setSaveMode);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ SessionRepositoryCustomizer<RedisIndexedSessionRepository> springBootSessionRepo
return (sessionRepository) -> {
map.from(sessionProperties
.determineTimeout(() -> serverProperties.getServlet().getSession().getTimeout()))
.to((timeout) -> sessionRepository.setDefaultMaxInactiveInterval((int) timeout.getSeconds()));
.to(sessionRepository::setDefaultMaxInactiveInterval);
map.from(redisSessionProperties::getNamespace).to(sessionRepository::setRedisKeyNamespace);
map.from(redisSessionProperties::getFlushMode).to(sessionRepository::setFlushMode);
map.from(redisSessionProperties::getSaveMode).to(sessionRepository::setSaveMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import org.springframework.http.ResponseCookie;
import org.springframework.session.MapSession;
import org.springframework.session.data.mongo.ReactiveMongoSessionRepository;
import org.springframework.session.data.redis.ReactiveRedisSessionRepository;

Expand Down Expand Up @@ -72,7 +73,8 @@ void defaultConfigWithCustomTimeout() {
"spring.data.mongodb.uri=" + mongoDb.getReplicaSetUrl()).run((context) -> {
ReactiveMongoSessionRepository repository = validateSessionRepository(context,
ReactiveMongoSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("maxInactiveIntervalInSeconds", 60);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
Duration.ofMinutes(1));
});
}

Expand All @@ -82,7 +84,8 @@ void defaultConfigWithCustomSessionTimeout() {
"spring.data.mongodb.uri=" + mongoDb.getReplicaSetUrl()).run((context) -> {
ReactiveMongoSessionRepository repository = validateSessionRepository(context,
ReactiveMongoSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("maxInactiveIntervalInSeconds", 60);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
Duration.ofMinutes(1));
});
}

Expand Down Expand Up @@ -126,8 +129,8 @@ private ContextConsumer<AssertableReactiveWebApplicationContext> validateSpringS
ReactiveMongoSessionRepository repository = validateSessionRepository(context,
ReactiveMongoSessionRepository.class);
assertThat(repository.getCollectionName()).isEqualTo(collectionName);
assertThat(repository).hasFieldOrPropertyWithValue("maxInactiveIntervalInSeconds",
ReactiveMongoSessionRepository.DEFAULT_INACTIVE_INTERVAL);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
MapSession.DEFAULT_MAX_INACTIVE_INTERVAL);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void defaultConfigWithCustomTimeout() {
this.contextRunner.withPropertyValues("spring.session.timeout=1m").run((context) -> {
ReactiveRedisSessionRepository repository = validateSessionRepository(context,
ReactiveRedisSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", 60);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", Duration.ofMinutes(1));
});
}

Expand All @@ -87,7 +87,7 @@ void defaultConfigWithCustomWebFluxTimeout() {
this.contextRunner.withPropertyValues("server.reactive.session.timeout=1m").run((context) -> {
ReactiveRedisSessionRepository repository = validateSessionRepository(context,
ReactiveRedisSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", 60);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", Duration.ofMinutes(1));
});
}

Expand Down Expand Up @@ -124,7 +124,7 @@ private ContextConsumer<AssertableReactiveWebApplicationContext> validateSpringS
ReactiveRedisSessionRepository repository = validateSessionRepository(context,
ReactiveRedisSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
MapSession.DEFAULT_MAX_INACTIVE_INTERVAL);
assertThat(repository).hasFieldOrPropertyWithValue("namespace", namespace);
assertThat(repository).hasFieldOrPropertyWithValue("saveMode", saveMode);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.autoconfigure.session;

import java.time.Duration;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -69,15 +71,15 @@ void defaultConfigWithCustomTimeout() {
this.contextRunner.withPropertyValues("spring.session.timeout=1m").run((context) -> {
HazelcastIndexedSessionRepository repository = validateSessionRepository(context,
HazelcastIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", 60);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", Duration.ofMinutes(1));
});
}

private void validateDefaultConfig(AssertableWebApplicationContext context) {
HazelcastIndexedSessionRepository repository = validateSessionRepository(context,
HazelcastIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
(int) new ServerProperties().getServlet().getSession().getTimeout().getSeconds());
new ServerProperties().getServlet().getSession().getTimeout());
HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class);
then(hazelcastInstance).should().getMap("spring:session:sessions");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.autoconfigure.session;

import java.time.Duration;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSource;
Expand Down Expand Up @@ -83,7 +85,7 @@ private void validateDefaultConfig(AssertableWebApplicationContext context) {
JdbcIndexedSessionRepository repository = validateSessionRepository(context,
JdbcIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
(int) new ServerProperties().getServlet().getSession().getTimeout().getSeconds());
new ServerProperties().getServlet().getSession().getTimeout());
assertThat(repository).hasFieldOrPropertyWithValue("tableName", "SPRING_SESSION");
assertThat(repository).hasFieldOrPropertyWithValue("cleanupCron", "0 * * * * *");
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema())
Expand Down Expand Up @@ -118,7 +120,7 @@ void customTimeout() {
this.contextRunner.withPropertyValues("spring.session.timeout=1m").run((context) -> {
JdbcIndexedSessionRepository repository = validateSessionRepository(context,
JdbcIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", 60);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", Duration.ofMinutes(1));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ private ContextConsumer<AssertableWebApplicationContext> validateSpringSessionUs
MongoIndexedSessionRepository repository = validateSessionRepository(context,
MongoIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("collectionName", collectionName);
assertThat(repository).hasFieldOrPropertyWithValue("maxInactiveIntervalInSeconds",
(int) timeout.getSeconds());
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", timeout);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private ContextConsumer<AssertableWebApplicationContext> validateSpringSessionUs
RedisIndexedSessionRepository repository = validateSessionRepository(context,
RedisIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
(int) new ServerProperties().getServlet().getSession().getTimeout().getSeconds());
new ServerProperties().getServlet().getSession().getTimeout());
assertThat(repository).hasFieldOrPropertyWithValue("namespace", keyNamespace);
assertThat(repository).hasFieldOrPropertyWithValue("flushMode", flushMode);
assertThat(repository).hasFieldOrPropertyWithValue("saveMode", saveMode);
Expand Down