Order SessionRepositoryCustomizer before other customizers
Update `JdbcSessionConfiguration` so the `SessionRepositoryCustomizer` used to map properties is always applied before other customizers. See gh-33514
This commit is contained in:
parent
8015f283b2
commit
19ce32dc34
|
@ -31,6 +31,8 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.session.SessionRepository;
|
||||
import org.springframework.session.config.SessionRepositoryCustomizer;
|
||||
|
@ -64,6 +66,7 @@ class JdbcSessionConfiguration {
|
|||
}
|
||||
|
||||
@Bean
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
SessionRepositoryCustomizer<JdbcIndexedSessionRepository> springBootSessionRepositoryCustomizer(
|
||||
SessionProperties sessionProperties, JdbcSessionProperties jdbcSessionProperties,
|
||||
ServerProperties serverProperties) {
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.springframework.session.data.mongo.MongoIndexedSessionRepository;
|
|||
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
|
||||
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
|
||||
import org.springframework.session.jdbc.JdbcIndexedSessionRepository;
|
||||
import org.springframework.session.jdbc.PostgreSqlJdbcIndexedSessionRepositoryCustomizer;
|
||||
import org.springframework.session.jdbc.config.annotation.SpringSessionDataSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
@ -243,6 +244,24 @@ class SessionAutoConfigurationJdbcTests extends AbstractSessionAutoConfiguration
|
|||
.hasBean("customInitializer"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenTheUserDefinesTheirOwnJdbcIndexedSessionRepositoryCustomizerThenDefaultConfigurationIsOverwritten() {
|
||||
String expectedCreateSessionAttributeQuery = """
|
||||
INSERT INTO SPRING_SESSION_ATTRIBUTES (SESSION_PRIMARY_ID, ATTRIBUTE_NAME, ATTRIBUTE_BYTES)
|
||||
VALUES (?, ?, ?)
|
||||
ON CONFLICT (SESSION_PRIMARY_ID, ATTRIBUTE_NAME)
|
||||
DO UPDATE SET ATTRIBUTE_BYTES = EXCLUDED.ATTRIBUTE_BYTES
|
||||
""";
|
||||
|
||||
this.contextRunner.withUserConfiguration(CustomJdbcIndexedSessionRepositoryCustomizerConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(JdbcSessionConfiguration.class)).run((context) -> {
|
||||
JdbcIndexedSessionRepository repository = validateSessionRepository(context,
|
||||
JdbcIndexedSessionRepository.class);
|
||||
assertThat(repository).hasFieldOrPropertyWithValue("createSessionAttributeQuery",
|
||||
expectedCreateSessionAttributeQuery);
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class SessionDataSourceConfiguration {
|
||||
|
||||
|
@ -289,4 +308,14 @@ class SessionAutoConfigurationJdbcTests extends AbstractSessionAutoConfiguration
|
|||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomJdbcIndexedSessionRepositoryCustomizerConfiguration {
|
||||
|
||||
@Bean
|
||||
PostgreSqlJdbcIndexedSessionRepositoryCustomizer postgreSqlJdbcIndexedSessionRepositoryCustomizer() {
|
||||
return new PostgreSqlJdbcIndexedSessionRepositoryCustomizer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue