Skip to content

Commit 867afdb

Browse files
committed
Replace JSR-250 annotations with standard Spring lifecycle callbacks
1 parent fb66cf3 commit 867afdb

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 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.
@@ -19,7 +19,6 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
import jakarta.annotation.PostConstruct;
2322
import jakarta.servlet.ServletContext;
2423
import jakarta.servlet.SessionCookieConfig;
2524
import jakarta.servlet.http.HttpSessionListener;
@@ -28,6 +27,7 @@
2827
import org.apache.commons.logging.LogFactory;
2928

3029
import org.springframework.beans.BeansException;
30+
import org.springframework.beans.factory.InitializingBean;
3131
import org.springframework.beans.factory.annotation.Autowired;
3232
import org.springframework.context.ApplicationContext;
3333
import org.springframework.context.ApplicationContextAware;
@@ -91,7 +91,7 @@
9191
* @see EnableSpringHttpSession
9292
*/
9393
@Configuration(proxyBeanMethods = false)
94-
public class SpringHttpSessionConfiguration implements ApplicationContextAware {
94+
public class SpringHttpSessionConfiguration implements InitializingBean, ApplicationContextAware {
9595

9696
private final Log logger = LogFactory.getLog(getClass());
9797

@@ -107,8 +107,8 @@ public class SpringHttpSessionConfiguration implements ApplicationContextAware {
107107

108108
private List<HttpSessionListener> httpSessionListeners = new ArrayList<>();
109109

110-
@PostConstruct
111-
public void init() {
110+
@Override
111+
public void afterPropertiesSet() {
112112
CookieSerializer cookieSerializer = (this.cookieSerializer != null) ? this.cookieSerializer
113113
: createDefaultCookieSerializer();
114114
this.defaultHttpSessionIdResolver.setCookieSerializer(cookieSerializer);

spring-session-hazelcast/spring-session-hazelcast.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ apply plugin: 'io.spring.convention.spring-module'
33
dependencies {
44
api project(':spring-session-core')
55
api "com.hazelcast:hazelcast"
6-
api "jakarta.annotation:jakarta.annotation-api"
76
api "org.springframework:spring-context"
87

98
testImplementation "jakarta.servlet:jakarta.servlet-api"

spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepository.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2022 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.
@@ -26,9 +26,6 @@
2626
import java.util.UUID;
2727
import java.util.concurrent.TimeUnit;
2828

29-
import jakarta.annotation.PostConstruct;
30-
import jakarta.annotation.PreDestroy;
31-
3229
import com.hazelcast.core.EntryEvent;
3330
import com.hazelcast.core.HazelcastInstance;
3431
import com.hazelcast.map.IMap;
@@ -40,6 +37,8 @@
4037
import org.apache.commons.logging.Log;
4138
import org.apache.commons.logging.LogFactory;
4239

40+
import org.springframework.beans.factory.DisposableBean;
41+
import org.springframework.beans.factory.InitializingBean;
4342
import org.springframework.context.ApplicationEventPublisher;
4443
import org.springframework.session.DelegatingIndexResolver;
4544
import org.springframework.session.FindByIndexNameSessionRepository;
@@ -116,7 +115,8 @@
116115
public class HazelcastIndexedSessionRepository
117116
implements FindByIndexNameSessionRepository<HazelcastIndexedSessionRepository.HazelcastSession>,
118117
EntryAddedListener<String, MapSession>, EntryEvictedListener<String, MapSession>,
119-
EntryRemovedListener<String, MapSession>, EntryExpiredListener<String, MapSession> {
118+
EntryRemovedListener<String, MapSession>, EntryExpiredListener<String, MapSession>, InitializingBean,
119+
DisposableBean {
120120

121121
/**
122122
* The default name of map used by Spring Session to store sessions.
@@ -164,14 +164,14 @@ public HazelcastIndexedSessionRepository(HazelcastInstance hazelcastInstance) {
164164
this.hazelcastInstance = hazelcastInstance;
165165
}
166166

167-
@PostConstruct
168-
public void init() {
167+
@Override
168+
public void afterPropertiesSet() {
169169
this.sessions = this.hazelcastInstance.getMap(this.sessionMapName);
170170
this.sessionListenerId = this.sessions.addEntryListener(this, true);
171171
}
172172

173-
@PreDestroy
174-
public void close() {
173+
@Override
174+
public void destroy() {
175175
this.sessions.removeEntryListener(this.sessionListenerId);
176176
}
177177

spring-session-hazelcast/src/test/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepositoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2022 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.
@@ -76,7 +76,7 @@ class HazelcastIndexedSessionRepositoryTests {
7676
void setUp() {
7777
given(this.hazelcastInstance.<String, MapSession>getMap(anyString())).willReturn(this.sessions);
7878
this.repository = new HazelcastIndexedSessionRepository(this.hazelcastInstance);
79-
this.repository.init();
79+
this.repository.afterPropertiesSet();
8080
}
8181

8282
@Test

0 commit comments

Comments
 (0)