Skip to content
New issue

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

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

Already on GitHub? # to your account

Remove spring.session.store-type in favor of a defined order for which implementation will win when multiple are available #27756

Closed
wilkinsona opened this issue Aug 18, 2021 · 3 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@wilkinsona
Copy link
Member

Looking at #27738 caused us to realize that the auto-configuration for Spring Session is more complex than it needs to be. To simplify it, we'd like to remove spring.session.store-type. In the unlikely event that multiple session repository implementations are available we should define and document which will be used, just as we do for JDBC connection pools today. If for some reason a user needs multiple session repository implementations on the classpath and our defined ordering doesn't meet their needs, they can define their own SessionRepository bean and cause the auto-configuration to back off.

@wilkinsona wilkinsona added the type: enhancement A general enhancement label Aug 18, 2021
@wilkinsona wilkinsona added this to the 3.x milestone Aug 18, 2021
@wilkinsona wilkinsona changed the title Remove spring.session.store-type in favor of a defined order for which implementation will win win multiple are available Remove spring.session.store-type in favor of a defined order for which implementation will win when multiple are available Aug 18, 2021
@scottfrederick scottfrederick added the status: blocked An issue that's blocked on an external project change label Nov 1, 2021
@wilkinsona wilkinsona added the for: team-meeting An issue we'd like to discuss as a team to make progress label Apr 26, 2022
@philwebb philwebb modified the milestones: 3.x, 3.0.x May 4, 2022
@philwebb philwebb removed for: team-meeting An issue we'd like to discuss as a team to make progress status: blocked An issue that's blocked on an external project change labels May 4, 2022
@mbhave mbhave self-assigned this Jun 13, 2022
@mbhave mbhave closed this as completed in 7cb53b3 Jun 22, 2022
@mbhave mbhave modified the milestones: 3.0.x, 3.0.0-M4 Jun 23, 2022
@wilkinsona
Copy link
Member Author

We've decided to reorder things a bit. We'd like the order to be:

  1. Redis
  2. JDBC
  3. Hazelcast
  4. Mongo

@ae-govau
Copy link

If for some reason a user needs multiple session repository implementations on the classpath and our defined ordering doesn't meet their needs, they can define their own SessionRepository bean and cause the auto-configuration to back off.

We stumbled across this today, when adding a optional support for a Redis session store to an app we look after which is deployed with different session stores by different users. Previously we thought we had been using spring.session.store-type to toggle between jdbc and hazelcast, but since support for the property was removed a while back, we must have just gotten lucky until now.

I tried implemented the suggestion above, e.g. the following looked to be a simple low-impact change to have the desired effect:

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.session.HazelcastSessionConfiguration;
import org.springframework.boot.autoconfigure.session.JdbcSessionConfiguration;
import org.springframework.boot.autoconfigure.session.RedisSessionConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
public class SessionStore {
    @ConditionalOnProperty(value = "myapp.session.store-type", havingValue = "hazelcast")
    @Import({HazelcastSessionConfiguration.class})
    static class HazelcastSession {}

    @ConditionalOnProperty(value = "myapp.web.session.store-type", havingValue = "jdbc")
    @Import({JdbcSessionConfiguration.class})
    static class JdbcSession {}

    @ConditionalOnProperty(value = "myapp.web.session.store-type", havingValue = "redis")
    @Import({RedisSessionConfiguration.class})
    static class RedisSession {}
}

The intention being that this would have the side effect of putting SessionRepository bean in, and thus sidestep the ordering issue. However this above won't compile because:

org.springframework.boot.autoconfigure.session.HazelcastSessionConfiguration is not public in org.springframework.boot.autoconfigure.session; cannot be accessed from outside package

Can anyone suggest a straight forward alternative approach?

@ae-govau
Copy link

I found these 3 classes which preliminary testing seems to work for our use-case using the pattern above:

import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration;
import org.springframework.session.hazelcast.config.annotation.web.http.HazelcastHttpSessionConfiguration;
import org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration;

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants