Skip to content

Commit aca350a

Browse files
vpaviceleftherias
authored andcommitted
Make Hazelcast session repository bean factory return type more specific
The declared return type of Hazelcast session repository bean factory method (i.e. HazelcastHttpSessionConfiguration#sessionRepository) was changed to SessionRepository<?> when support for Hazelcast 4 was added. This breaks Spring Boot's ability to auto-configure sessions endpoint, which is @ConditionalOnBean(FindByIndexNameSessionRepository.class), as the current return type is not specific enough to satisfy this condition. This commit changes the return type of Hazelcast session repository bean factory method to FindByIndexNameSessionRepository<?>. Closes: gh-1907
1 parent d8af719 commit aca350a

File tree

7 files changed

+29
-3
lines changed

7 files changed

+29
-3
lines changed

spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/config/annotation/web/http/HazelcastHttpSessionConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2020 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,12 +30,12 @@
3030
import org.springframework.context.annotation.ImportAware;
3131
import org.springframework.core.annotation.AnnotationAttributes;
3232
import org.springframework.core.type.AnnotationMetadata;
33+
import org.springframework.session.FindByIndexNameSessionRepository;
3334
import org.springframework.session.FlushMode;
3435
import org.springframework.session.IndexResolver;
3536
import org.springframework.session.MapSession;
3637
import org.springframework.session.SaveMode;
3738
import org.springframework.session.Session;
38-
import org.springframework.session.SessionRepository;
3939
import org.springframework.session.config.SessionRepositoryCustomizer;
4040
import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration;
4141
import org.springframework.session.hazelcast.Hazelcast4IndexedSessionRepository;
@@ -85,7 +85,7 @@ public class HazelcastHttpSessionConfiguration extends SpringHttpSessionConfigur
8585
}
8686

8787
@Bean
88-
public SessionRepository<?> sessionRepository() {
88+
public FindByIndexNameSessionRepository<?> sessionRepository() {
8989
if (hazelcast4) {
9090
return createHazelcast4IndexedSessionRepository();
9191
}

spring-session-samples/spring-session-sample-boot-hazelcast/spring-session-sample-boot-hazelcast.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apply plugin: 'io.spring.convention.spring-sample-boot'
33
dependencies {
44
compile project(':spring-session-hazelcast')
55
compile "org.springframework.boot:spring-boot-starter-web"
6+
compile "org.springframework.boot:spring-boot-starter-actuator"
67
compile "org.springframework.boot:spring-boot-starter-thymeleaf"
78
compile "org.springframework.boot:spring-boot-starter-security"
89
compile "com.hazelcast:hazelcast"

spring-session-samples/spring-session-sample-boot-hazelcast/src/integration-test/java/sample/BootTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424
import sample.pages.LoginPage;
2525

2626
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.actuate.session.SessionsEndpoint;
2728
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
2829
import org.springframework.boot.test.context.SpringBootTest;
2930
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
31+
import org.springframework.context.ApplicationContext;
32+
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
3033
import org.springframework.test.web.servlet.MockMvc;
3134
import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder;
3235

36+
import static org.assertj.core.api.Assertions.assertThat;
37+
3338
/**
3439
* @author Ellie Bahadori
3540
*/
@@ -52,6 +57,12 @@ void tearDown() {
5257
this.driver.quit();
5358
}
5459

60+
@Test // gh-1905
61+
void contextLoads(ApplicationContext context) {
62+
assertThat(context.getBeansOfType(HazelcastIndexedSessionRepository.class)).hasSize(1);
63+
assertThat(context.getBeansOfType(SessionsEndpoint.class)).hasSize(1);
64+
}
65+
5566
@Test
5667
void home() {
5768
LoginPage login = HomePage.go(this.driver);
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
management.endpoints.web.exposure.include=sessions
12
spring.security.user.password=password

spring-session-samples/spring-session-sample-boot-hazelcast4/spring-session-sample-boot-hazelcast4.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dependencies {
44
compile project(':spring-session-hazelcast')
55
compile project(':hazelcast4')
66
compile "org.springframework.boot:spring-boot-starter-web"
7+
compile "org.springframework.boot:spring-boot-starter-actuator"
78
compile "org.springframework.boot:spring-boot-starter-thymeleaf"
89
compile "org.springframework.boot:spring-boot-starter-security"
910
compile "com.hazelcast:hazelcast:4.2.2"

spring-session-samples/spring-session-sample-boot-hazelcast4/src/integration-test/java/sample/BootTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424
import sample.pages.LoginPage;
2525

2626
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.actuate.session.SessionsEndpoint;
2728
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
2829
import org.springframework.boot.test.context.SpringBootTest;
2930
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
31+
import org.springframework.context.ApplicationContext;
32+
import org.springframework.session.hazelcast.Hazelcast4IndexedSessionRepository;
3033
import org.springframework.test.web.servlet.MockMvc;
3134
import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder;
3235

36+
import static org.assertj.core.api.Assertions.assertThat;
37+
3338
@AutoConfigureMockMvc
3439
@SpringBootTest(webEnvironment = WebEnvironment.MOCK)
3540
class BootTests {
@@ -49,6 +54,12 @@ void tearDown() {
4954
this.driver.quit();
5055
}
5156

57+
@Test // gh-1905
58+
void contextLoads(ApplicationContext context) {
59+
assertThat(context.getBeansOfType(Hazelcast4IndexedSessionRepository.class)).hasSize(1);
60+
assertThat(context.getBeansOfType(SessionsEndpoint.class)).hasSize(1);
61+
}
62+
5263
@Test
5364
void home() {
5465
LoginPage login = HomePage.go(this.driver);
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
management.endpoints.web.exposure.include=sessions
12
spring.security.user.password=password

0 commit comments

Comments
 (0)