From 64aade856c1e98838c90d8751d0295019c79498e Mon Sep 17 00:00:00 2001 From: Nusrat Shakarov Date: Wed, 29 May 2024 07:14:28 +0200 Subject: [PATCH] IGNITE-22352 Fix bean creation order (#270) --- .../sessions/EnableIgniteHttpSession.java | 1 - .../IgniteHttpSessionConfiguration.java | 81 +++++++------------ 2 files changed, 31 insertions(+), 51 deletions(-) diff --git a/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/EnableIgniteHttpSession.java b/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/EnableIgniteHttpSession.java index 74dadcf83..7301203af 100644 --- a/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/EnableIgniteHttpSession.java +++ b/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/EnableIgniteHttpSession.java @@ -22,7 +22,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - import org.apache.ignite.Ignite; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; diff --git a/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfiguration.java b/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfiguration.java index a06006bb0..86b3c730c 100644 --- a/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfiguration.java +++ b/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/IgniteHttpSessionConfiguration.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import jakarta.annotation.PostConstruct; import org.apache.ignite.Ignite; import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.client.IgniteClient; @@ -68,9 +67,6 @@ public class IgniteHttpSessionConfiguration extends SpringHttpSessionConfigurati /** */ private SaveMode saveMode = SaveMode.ON_SET_ATTRIBUTE; - /** */ - private SessionProxy sessions; - /** */ private ApplicationEventPublisher applicationEvtPublisher; @@ -80,17 +76,6 @@ public class IgniteHttpSessionConfiguration extends SpringHttpSessionConfigurati /** */ private List> sesRepoCustomizers; - /** */ - private Object connObj; - - /** - * @return Session repository. - */ - @Bean - public SessionRepository sessionRepository() { - return createIgniteIndexedSessionRepository(); - } - /** * @param maxInactiveIntervalInSeconds Maximum inactive interval in sec. */ @@ -119,36 +104,6 @@ public void setSaveMode(SaveMode saveMode) { this.saveMode = saveMode; } - /** - * @param springSesIgnite Ignite session. - * @param ignite Ignite instance provider. - * @param cli Ignite client instance provider. - */ - @Autowired - public void setSessions( - @SpringSessionIgnite ObjectProvider springSesIgnite, - ObjectProvider ignite, - ObjectProvider cli - ) { - Object connObj = springSesIgnite.getIfAvailable(); - - if (connObj == null) - connObj = ignite.getIfAvailable(); - - if (connObj == null) - connObj = cli.getIfAvailable(); - - this.connObj = connObj; - } - - /** - * Init sessions. - */ - @PostConstruct - public void initSessions() { - this.sessions = createSessionProxy(this.connObj); - } - /** * @param applicationEvtPublisher Application event publisher. */ @@ -189,8 +144,28 @@ public void setSessionRepositoryCustomizer( this.saveMode = attrs.getEnum("saveMode"); } - /** */ - private SessionProxy createSessionProxy(Object connObj) { + /** + * Session cache proxy. + * + * @param springSesIgnite Ignite session. + * @param igniteProvider Ignite instance provider. + * @param igniteClientProvider Ignite client instance provider. + * @return Session cache proxy. + */ + @Bean + public SessionProxy sessionProxy( + @SpringSessionIgnite ObjectProvider springSesIgnite, + ObjectProvider igniteProvider, + ObjectProvider igniteClientProvider + ) { + Object connObj = springSesIgnite.getIfAvailable(); + + if (connObj == null) + connObj = igniteProvider.getIfAvailable(); + + if (connObj == null) + connObj = igniteClientProvider.getIfAvailable(); + List initQueries = Arrays.asList( new SqlFieldsQuery("CREATE TABLE IF NOT EXISTS IgniteSession (" + " id VARCHAR PRIMARY KEY," + @@ -224,9 +199,15 @@ private SessionProxy createSessionProxy(Object connObj) { "Object " + connObj + " can not be used to connect to the Ignite cluster."); } - /** */ - private IgniteIndexedSessionRepository createIgniteIndexedSessionRepository() { - IgniteIndexedSessionRepository sesRepo = new IgniteIndexedSessionRepository(this.sessions); + /** + * Session repository bean. + * + * @param sesProxy Session cache proxy. + * @return Session repository. + */ + @Bean + public SessionRepository sessionRepository(SessionProxy sesProxy) { + IgniteIndexedSessionRepository sesRepo = new IgniteIndexedSessionRepository(sesProxy); sesRepo.setApplicationEventPublisher(this.applicationEvtPublisher); if (this.idxResolver != null) sesRepo.setIndexResolver(this.idxResolver);